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

Can someone tell me whats wrong with this script, It's an if statement?

Asked by 3 years ago
Edited 3 years ago

This is a server script/ normal script inside server script service. What is wrong is when 1 player joins the person is allocated a base and the value of owner changes to their name whereas when player 2 joins the value of owner doesn't change

game.Players.PlayerAdded:Connect(function(plr)


    if workspace.Bases.Blue.Owner.Value == "" then
        workspace.Bases.Blue.Owner.Value = plr.Name

    elseif workspace.Bases.Red.Owner.Value == "" then
        workspace.Bases.Red.Owner.Value = plr.Name

    elseif workspace.Bases.Yellow.Owner.Value == "" then
        workspace.Bases.Yellow.Owner.Value = plr.Name

    elseif workspace.Bases.Green.Owner.Value == "" then
        workspace.Bases.Green.Owner.Value = plr.Name



end

2 answers

Log in to vote
1
Answered by 3 years ago

If I'm correct, you haven't properly closed the whole script either. Try turning on the roblox studio script analyzer which detects things you could better or would error normally:

game.Players.PlayerAdded:Connect(function(plr)

    if workspace.Bases.Blue.Owner.Value == nil then -- turning the value into nil is better than "" since you define the value to be " " instead of nothing.
        workspace.Bases.Blue.Owner.Value = plr.Name

    elseif workspace.Bases.Red.Owner.Value == nil then
        workspace.Bases.Red.Owner.Value = plr.Name

    elseif workspace.Bases.Yellow.Owner.Value == nil then
        workspace.Bases.Yellow.Owner.Value = plr.Name

    elseif workspace.Bases.Green.Owner.Value == nil then
        workspace.Bases.Green.Owner.Value = plr.Name

end -- ends the if then elseif loop
end) -- this will also define the end of the script executed within the function

come back and tell me if it works

0
I forgot the end FluffySheep46209 369 — 3y
Ad
Log in to vote
0
Answered by
6zk8 95
3 years ago
game.Players.PlayerAdded:Connect(function(plr)
    if game.workspace.Bases.Blue.Owner.Value == nil  then
        game.workspace.Bases.Blue.Owner.Value = plr.Name

    elseif game.workspace.Bases.Red.Owner.Value == nil then
        game.workspace.Bases.Red.Owner.Value = plr.Name

    elseif game.workspace.Bases.Yellow.Owner.Value == nil then
        game.workspace.Bases.Yellow.Owner.Value = plr.Name

    elseif game.workspace.Bases.Green.Owner.Value == nil then
        game.workspace.Bases.Green.Owner.Value = plr.Name
end

Try this

Answer this question