Why does My teleporter part Not teleport to another part - lua

I am currently working on a game teleporter in Roblox (If you are unfamiliar with this, you touch a part and It takes you to a waiting area to soon be teleported to the game) Right now I am having trouble with the part that teleports you to that waiting area. (the name of the part teleporting you is called Teleporter. The name of the part you are being teleported to is called Lob)
The code I had put In was `
local Lob = game.Workspace.Lob
function Teleport()
game.Workspace.Teleporter.Touched:Connect(game.Players.LocalPlayer:MoveTo(Lob))
end
game.Workspace.Teleporter.Touched:Connect(Teleport)
What i got wasServerScriptService.Script:4: attempt to index nil with 'MoveTo'`

You're connecting the touched event inside of the function and outside of it.
Could you possibly do something like
function Teleport()
game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.CFrame = Lob.CFrame)
end
workspace.Teleporter.Touched:Connect(Teleport)

Related

part not changing position roblox studio

So, I scripted a chat code detector in Roblox; I wanted to move an object (Elevator) to a specific position. The object does not move at all.
Things I have tried:
Using CFrame to move the part instead of Vector3
Keeping the part in the right position but disabling its scripts until I activate it
Rewriting the script entirely in case it was a problem with the rest of the script
However the strangest thing of all:
At the bottom of Roblox Studio there is a bar that allows you to execute commands. When I run the exact piece of code that moves the object inside that bar, it moves. I do not know what is even happening.
local message='thestars'
function onChatted(msg,recipient,speaker)
local source=string.lower(msg)
if (msg==message) then
game.Workspace.Elevator.Position=Vector3.new(99,-57,72)
script.NOISE:Play()
game.Workspace.radio.Radio.Union.Sound:Pause()
while true do
game.Workspace.bruh.Transparency-=.025
wait()
end
end
end
function onPlayerEntered(newPlayer)
newPlayer.Chatted:connect(function(msg,recipient) onChatted(msg,recipient,newPlayer) end)
end
game.Players.PlayerAdded:connect(onPlayerEntered)
I did this by making a local script so that when the player chats "thestars", it fires a remote event to the server which does the action. Try that:
Local script:
local checkMessage = function(msg,recipient,speaker)
local message='thestars'
if msg == message then
game.ReplicatedStorage:WaitForChild(urthing):FireServer()
end
end
game.Players.LocalPlayer.Chatted:Connect(checkMessage)
Server script:
local myFunction = function()
local source=string.lower(msg)
game.Workspace.Elevator.Position=Vector3.new(99,-57,72)
script.NOISE:Play()
game.Workspace.radio.Radio.Union.Sound:Pause()
while true do
game.Workspace.bruh.Transparency-=.025
wait()
end
end
game.ReplicatedStorage:WaitForChild("thingyremote").OnServerEvent:Connect(myFunction)

What does "attempt to index function with 'Connect'" mean in Roblox?

local Player = game.Players.LocalPlayer
local PlayerCash = Player:WaitForChild("leaderstats"):WaitForChild("Strength")
local Mouse = Player:GetMouse()
local amount = 50
script.Parent.Activate:Connect(function()
game.Players.LocalPlayer.leaderstats.money.Value = game.Players.LocalPlayer.leaderstats.money.Value + amount
end)
I am trying to make a code to give Strength when you click. When I press 'Play' it doesn't work. All it says in the output is
'attempt to index function with 'Connect'.'
The error "attempt to index [type] with [field name]" means that you are incorrectly using something like an object, and you are trying to access some field on it.
In your case, this error is pointing at the line : script.Parent.Activate:Connect.This says that script.Parent.Activate is a function and not a table, and you cannot call Connect on a function. This is just to help us figure out what is wrong with our code.
Since you working with Tools, there is a simple fix. Instead of using the Activate function, you are looking for the Activated event. So just change update that line like this :
script.Parent.Activated:Connect(function()
It connects a function to an event that happened, like this:
local tool = script.Parent
-- It connects the event (the tool being equipped) to a function.
tool.Equipped:Connect(function()
-- CODE
end)
Also, the answer above is how you can fix your problem and here's a shortcut: You have defined "Player" and you could've used it inside the function. Have a great day and God bless everyone here.

roblox studio plr.Name == ""

i'm making a script that detects a person using their name however I can't seem to get it working. Please also point out any mistakes I have done in my script it would help a lot.
game.Workspace:WaitForChild("Console")
print("Waited")
game.Players.PlayerAdded:Connect(function(plr)
print("Connected")
if game.Workspace.Console and plr.Name == "wojciechpa2007" then
local Console = game.Lighting.Console:Clone()
Console.Parent = plr.Startergui
print("Cloned")
elseif
not game.Workspace.Console and plr.Name == "wojciechpa2007" then
plr.Startergui.Console:Destroy()
print("Destroyed")
end
end)
Heyo,
This script has a race-condition in it. Your first line game.Workspace:WaitForChild("Console") will block execution of the rest of your script until the object is loaded, or a timeout is reached.
This means that it is possible that a player could join the game before the script can listen for the game.Players.PlayerAdded signal.
Also StarterGui does not exist on specific player. It exists at the game level and is a bucket that dumps its stuff into a Player's PlayerGui when that player's character loads into the game.
So to fix your script, you could try something like this :
-- right away connect to the PlayerAdded signal
game.Players.PlayerAdded:Connect(function(plr)
print("Player Joined!", plr.Name, plr.UserId)
-- do something special if wojciechpa2007 joins
if plr.Name == "wojciechpa2007" then
print("wojciechpa2007 joined! Adding console!")
-- add the special console into the player's PlayerGui for when they load
local Console = game.Lighting.Console:Clone()
Console.Parent = plr.PlayerGui
end
end)
Some recommendations and things to be careful about here :
It's safer to check a player's UserId than it is to check their name. Roblox lets you change your name, but you UserId is always the same.
Putting something into your StarterGui will make it show up in your PlayerGui the next time your character loads. But if your character is already loaded, you won't see it until the next time you respawn.
If your Console object is some kind of GUI element, make sure that it is parented to a ScreenGui object before you insert it into the Player. Otherwise it just won't show up.
Hope this helps!

ROBLOX Studio function to call function for each door to open

I'm pretty new to ROBLOX development and don't really know how to make the objects talk just yet.
I have 16 cells all with an individual open and close button. Those work. I want to create a button that will open all doors at once.
function onClicked()
script.Parent.Parent.Door.Transparency = 1
script.Parent.Parent.Door.CanCollide= false
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
The above function is on each cell and works. I would like to loop through each one and fire it when I click a different button. I've been looking into getting each object with the same names but haven't been able to iterate through it.
The below code is my attempt to get it to fire off each one!
local part = workspace.OpenButton
local clickDetector = Instance.new("ClickDetector")
local function onMouseClick(player)
for _, child in pairs(workspace.PrisonCell:GetChildren()) do
print(child)
child:connect(child.Door.onClicked)
end
end
clickDetector.Parent = part
part.Parent = workspace
clickDetector.MouseClick:connect(onMouseClick)
Any help with this would be greatly appreciated!
You could do something similar to this to open all of the prison doors at once:
local part = workspace.OpenButton
local clickDetector = Instance.new("ClickDetector")
local function onMouseClick(player)
for _, child in pairs(workspace.PrisonCell:GetChildren()) do
child.Door.Transparency = 1
child.Door.CanCollide = false
end
end
clickDetector.Parent = part
part.Parent = workspace
clickDetector.MouseClick:connect(onMouseClick)
The downside to using the solution above is that if you want to change the door opening script, you would have to change it in both the individual cell buttons as well as this master button script. If you think this might be a problem in the future, I would consider writing a master script somewhere in ServerScriptService that uses BindableEvents for communcation with the button clicking scripts in order to keep the door opening function in one place.

Lua: addEventListner cannot be nil:nil stack traceback

ok, I've been starring at this error message for better part of a day now.
I'm trying to make a simple eventlistner to run when someone touches a button. The problem is that hower ever I decided to name it it says it's nil and cannot be used.
I'm working on a scene with the name "scene", self.view named "sceneGroup". The rectangle I try to add a listner to is called "mMnew" and is in the group called "mMnewU".
I've tried to change the name between all of those. At first I hade problem with adding the eventlistener but solved it, problem was not the same sulution worked for the listners name.
Listner:
function scene.mMnewUeser:touch(event)
if(event.phase == "begun")then
local test1 = display.newRect(100,150,40,40)
test1:setFillColor(0,1,0)
print("Touch found")
end
end
Added listner:
scene:addEventListener("touch", scene.mMnewUeser)
I'm still pretty green with this language and used to code in JavaC, php, html, sql and AS3.0. Sorry for my rockie problems!
UPDATE:
After adding a few simple checkpoints check in the code, it would seam that it refuses to run the function scene:create(event) my scene does hwoerver get created by local composer = require("composer")
local scene = composer.newScene()
This
function scene.mMnewUeser:touch(event)
is not the correct syntax. You probably meant to have:
function scene:mMnewUeser(event)
which means you're adding new method with a name mMnewUeser to scene object. Then you can just use it as touch listener the way you did in the last line of code. See an explanation of the difference between . and : here.

Resources