Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make my .Touched function run? Doesn't run code inside function at all.

Asked by 5 years ago
Edited 5 years ago

This question has been solved by the original poster.
function Teleport(hit)
    if hit and hit.Parent:FindFirstChild("Humanoid") == true then
        script.Parent.Number.Value = math.random(1,8)

        if script.Parent.Number.Value == 1 then
        hit.Parent.Humanoid:MoveTo(S1)


        end
    end
end


script.Parent.Touched:connect(Teleport)

I'm making this code where whenever a player touches this part that this script is connected to, it'll choose a random number and depending on what number it lands on it will decide which spawn they'll go to. I went to test it before connecting the rest of the spawns to their own #, but I realized whenever I touch the part that is supposed to teleport you to one of the spawn points it doesn't even randomize (change) the IntValue that's supposed to decide the number.

There are no errors in the output, so I have no idea why it's not running.

0
can we see the structure of script.Parent? royaltoe 5144 — 5y
0
It's all good, I solved it. But the second if statement isn't running. I can't figure out why. The S1 variable path just links to a part in the workspace. EstrangedFisherman 51 — 5y
0
^ Figured that out also, just needed to change it to S1.Position. But now I just need to figure out how to make the character teleport instead of walking over. I basically solved my own question. EstrangedFisherman 51 — 5y
0
S1 isn't declared as a variable. Cvllapse 30 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

Figured it out. All I needed to do was remove the:

== true

part of the code and it ran fine. I also made it an anonymous function, but I'm not sure if I needed to do that for it to run.

Ad

Answer this question