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

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

Asked by
iiii676 23
3 years ago
Edited 3 years ago

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?

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. chess123mate 5873 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

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)
Ad
Log in to vote
0
Answered by 3 years ago

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

Answer this question