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

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

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.

4 comments

0

can we see the structure of script.Parent?

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.

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.

0

S1 isn't declared as a variable.

1 answer

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.

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