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

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

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

✓ Accepted answer

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

1 comment

0

I forgot the end

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

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