-2

# 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


~~~~~~~~~~~~~~~~~

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 2mania 9 — 15d
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 Kingu_Criminal 170 — 14d

0

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! ^^