Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does my script still start after I make it a function?

So im making a admin panel and theres a button to teleport to players and this script automaticlly starts for some reason even tho i didnt click the button for it to start im still a starter can someone please help me~~~~~~~~~~~~~~~~~ if script.Parent.MouseButton1Click then local p1 = game.Players.LocalPlayer.Character.HumanoidRootPart local p2 = "InsertPlayerHere"

local pos = p1.CFrame
p2 = script.Parent.Parent.Player.Text
p1.CFrame = game.Players[p2].Character.HumanoidRootPart.CFrame



p1.CFrame = pos
end


2 comments

0

if script.Parent.MouseButton1Click then local p1 = game.Players.LocalPlayer.Character.HumanoidRootPart local p2 = "InsertPlayerHere" local pos = p1.CFrame p2 = script.Parent.Parent.Player.Text p1.CFrame = game.Players[p2].Character.HumanoidRootPart.CFrame p1.CFrame = pos end

0

You can't use If for Signal, you have to use connection. also if the text isn't a player's name then the script will error

1 answer

✓ Accepted answer

In your script, you're trying to check if MouseButton1Click exist inside script.Parent, and it exists because it's an event and event will automatically be put inside an instance by the roblox game engine. Instead, use events properly like this script below.

script.Parent.MouseButton1Click:Connect(function()
	local p1 = game.Players.LocalPlayer.Character.HumanoidRootPart
	local p2 = script.Parent.Parent.Player.Text
	local pos = p1.CFrame
	p1.CFrame = game.Players:WaitForChild(p2).Character.HumanoidRootPart.CFrame
end)

I hope the script above works and I hope this helped! ^^

Learn more about events: Documentation Wiki Fandom

This discussion is preserved as it was. New answers, comments, and votes are closed.