Ad
Log in to vote
-2

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

Asked by
2mania 9
15 days ago

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

1 answer

Log in to vote
0
Answered by 14 days ago

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

Ad

Answer this question