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

Script not working even though no errors produced. Anyone know why?

For some reason, this script doesn't work even though no errors are printed

script.Parent.Touched:Connect(function(hit)
	if game.Players:GetPlayerFromCharacter(hit.Parent)then
		if game.ReplicatedStorage.Teams.Value == 0
			hit.Parent.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(60.293, -88.617, -67))--Change to Position
			game.ReplicatedStorage.Teams.Value = game.ReplicatedStorage.Teams.Value + 1
		if game.ReplicatedStorage.Teams.Value == 1 then
			hit.Parent.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(60.293, -90.617, 49.5))--Change to Position
			game.ReplicatedStorage.Teams.Value = game.ReplicatedStorage.Teams.Value + 1
		if game.ReplicatedStorage.Teams.Value == 2 then
			hit.Parent.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(60.293, -88.617, -67))--Change to Position
			game.ReplicatedStorage.Teams.Value = game.ReplicatedStorage.Teams.Value + 1
		if game.ReplicatedStorage.Teams.Value == 3 then
			hit.Parent.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(60.293, -90.617, 49.5))--Change to Position
			game.ReplicatedStorage.Teams.Value = game.ReplicatedStorage.Teams.Value + 1
		if game.ReplicatedStorage.Teams.Value == 4 then
			hit.Parent.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(60.293, -88.617, -67))--Change to Position
			game.ReplicatedStorage.Teams.Value = game.ReplicatedStorage.Teams.Value + 1
		if game.ReplicatedStorage.Teams.Value == 5 then
			hit.Parent.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(60.293, -90.617, 49.5))--Change to Position
			game.ReplicatedStorage.Teams.Value = game.ReplicatedStorage.Teams.Value + 1
		end
	end
	end)

Its meant to divide 6 players into 2 teams, with each of the 2 teleport spots being the team bases. If the number is odd then they are on the blue team but if it's even they are on the green team, every time someone touches the block the number goes up by one. If the script is sloppy I'm sorry, I'm new to scripting. It teleports the player when they touch the block. But for some reason, it isn't teleporting them.

Also if anyone has a more organized version of the script I would gladly use it.

So, If you know why this isn't working, could you help me, please?

1 comment

0

If it isn't outputting any errors, it may be because you have placed a Script where only a LocalScript would run or vice versa. Open the Script Analysis window and it'll complain about syntax errors (and other probable mistakes) without you having to run the place to find out.

2 answers

✓ Accepted answer

If statements start with an if, and always terminate with end. You should not put another if statement unless it is nested within the first one, or you have already ended the first one. What you can put between the if and end is elseif.

Try this:

script.Parent.Touched:Connect(function(hit)
    if game.Players:GetPlayerFromCharacter(hit.Parent)then
        if game.ReplicatedStorage.Teams.Value == 0
            hit.Parent.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(60.293, -88.617, -67))--Change to Position
            game.ReplicatedStorage.Teams.Value = game.ReplicatedStorage.Teams.Value + 1
        elseif game.ReplicatedStorage.Teams.Value == 1 then
            hit.Parent.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(60.293, -90.617, 49.5))--Change to Position
            game.ReplicatedStorage.Teams.Value = game.ReplicatedStorage.Teams.Value + 1
        elseif game.ReplicatedStorage.Teams.Value == 2 then
            hit.Parent.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(60.293, -88.617, -67))--Change to Position
            game.ReplicatedStorage.Teams.Value = game.ReplicatedStorage.Teams.Value + 1
        elseif game.ReplicatedStorage.Teams.Value == 3 then
            hit.Parent.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(60.293, -90.617, 49.5))--Change to Position
            game.ReplicatedStorage.Teams.Value = game.ReplicatedStorage.Teams.Value + 1
        elseif game.ReplicatedStorage.Teams.Value == 4 then
            hit.Parent.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(60.293, -88.617, -67))--Change to Position
            game.ReplicatedStorage.Teams.Value = game.ReplicatedStorage.Teams.Value + 1
        elseif game.ReplicatedStorage.Teams.Value == 5 then
            hit.Parent.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(60.293, -90.617, 49.5))--Change to Position
            game.ReplicatedStorage.Teams.Value = game.ReplicatedStorage.Teams.Value + 1
        end
    end
end)

There aren't any "ends" in the if statements in between.

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