Why doesn't the elseif part of this script not work? Everything else in the whole script works besides this one part, please help.
bin = script.Parent function onTouched(bin) local character = bin.Parent local player = game.Players:GetPlayerFromCharacter(character) local team = player.TeamColor if character and player then if team == BrickColor.new("Medium stone grey") then --Raider Group Color if workspace:FindFirstChild("Active") then end if workspace:FindFirstChild("Camera") then game.Workspace.Camera.Name = "Active" game.Workspace.Light.BrickColor = team local hint = Instance.new('Hint', workspace) hint.Text = "Raiders have taken the base! 20 Minutes Till Raiders have won!" wait(3) game.Workspace.Message:Remove() game.Workspace["Owned By: (Group Name)"].Name = "Owned By: Raiders" game.Workspace.Glass.BrickColor = BrickColor.New("Medium stone grey") --Raider Group Color for _, part in pairs(game.Workspace.Colors:GetChildren()) do part.BrickColor = team end if workspace:FindFirstChild("Camera") then for progress = 5, 100, 5 do wait(60) local hint = Instance.new('Hint', workspace) hint.Text = progress .. "%" end end elseif team == BrickColor.new("Really red") then --Main Group Team Color if workspace:FindFirstChild("Active") then game.Workspace.Active.Name = "Camera" game.Workspace.Light.BrickColor = team game.Workspace["Owned By: Raiders"].Name = "Owned By: (Group Name)" --Insert Group Name Here local hint = Instance.new('Hint', workspace) hint.Text = "(Group Name) has taken back the base!" --Insert Group Name Here wait(3) hint:Remove() for _, part in pairs(game.Workspace.Colors:GetChildren()) do part.BrickColor = team end end end end end end bin.Touched:connect(onTouched)
I believe your problem has to do with the placement of you elseif statement. It will help a lot if you properly space every thing out (see the Lua Style Guide for more information):
bin = script.Parent function onTouched(bin) local character = bin.Parent local player = game.Players:GetPlayerFromCharacter(character) local team = player.TeamColor if character and player then if team == BrickColor.new("Medium stone grey") then --Raider Group Color if workspace:FindFirstChild("Active") then end if workspace:FindFirstChild("Camera") then game.Workspace.Camera.Name = "Active" game.Workspace.Light.BrickColor = team local hint = Instance.new('Hint', workspace) hint.Text = "Raiders have taken the base! 20 Minutes Till Raiders have won!" wait(3) game.Workspace.Message:Remove() game.Workspace["Owned By: (Group Name)"].Name = "Owned By: Raiders" game.Workspace.Glass.BrickColor = BrickColor.New("Medium stone grey") --Raider Group Color for _, part in pairs(game.Workspace.Colors:GetChildren()) do part.BrickColor = team end if workspace:FindFirstChild("Camera") then for progress = 5, 100, 5 do wait(60) local hint = Instance.new('Hint', workspace) hint.Text = progress .. "%" end end elseif team == BrickColor.new("Really red") then --Main Group Team Color if workspace:FindFirstChild("Active") then game.Workspace.Active.Name = "Camera" game.Workspace.Light.BrickColor = team game.Workspace["Owned By: Raiders"].Name = "Owned By: (Group Name)" --Insert Group Name Here local hint = Instance.new('Hint', workspace) hint.Text = "(Group Name) has taken back the base!" --Insert Group Name Here wait(3) hint:Remove() for _, part in pairs(game.Workspace.Colors:GetChildren()) do part.BrickColor = team end end end end end end bin.Touched:connect(onTouched)
As you can see, the elseif statement is going to the if workspace:FindFirstChild("Camera") then
line instead of the line I think you want it to go to, the if team == BrickColor.new("Medium stone grey") then --Raider Group Color
line. In order to fix it, if that is your problem, then you simply need rearrange you end statements:
bin = script.Parent function onTouched(bin) local character = bin.Parent local player = game.Players:GetPlayerFromCharacter(character) local team = player.TeamColor if character and player then if team == BrickColor.new("Medium stone grey") then --Raider Group Color if workspace:FindFirstChild("Active") then end if workspace:FindFirstChild("Camera") then game.Workspace.Camera.Name = "Active" game.Workspace.Light.BrickColor = team local hint = Instance.new('Hint', workspace) hint.Text = "Raiders have taken the base! 20 Minutes Till Raiders have won!" wait(3) game.Workspace.Message:Remove() game.Workspace["Owned By: (Group Name)"].Name = "Owned By: Raiders" game.Workspace.Glass.BrickColor = BrickColor.New("Medium stone grey") --Raider Group Color for _, part in pairs(game.Workspace.Colors:GetChildren()) do part.BrickColor = team end if workspace:FindFirstChild("Camera") then for progress = 5, 100, 5 do wait(60) local hint = Instance.new('Hint', workspace) hint.Text = progress .. "%" end end end elseif team == BrickColor.new("Really red") then --Main Group Team Color if workspace:FindFirstChild("Active") then game.Workspace.Active.Name = "Camera" game.Workspace.Light.BrickColor = team game.Workspace["Owned By: Raiders"].Name = "Owned By: (Group Name)" --Insert Group Name Here local hint = Instance.new('Hint', workspace) hint.Text = "(Group Name) has taken back the base!" --Insert Group Name Here wait(3) hint:Remove() for _, part in pairs(game.Workspace.Colors:GetChildren()) do part.BrickColor = team end end end end end bin.Touched:connect(onTouched)
It's because of there are two of the same variable which you have as one being the script's parent bin = script.Parent
and the other being the object that hit the script's parent function onTouched(bin)
. It's confusing the script and the script will basically ignore the variable you have in the event. Instead of searching for the part's parent that hit the brick to begin with, you're trying to find the script's parent, which leads to the script not being able to find the player. All you have to do is change these two lines,
function onTouched(bin) local character = bin.Parent
to;
function onTouched(hit) local character = hit.Parent
BEFORE ANYONE DOWNVOTES THIS, YOU TRY IT. I HAVE RENAMED THE TAG EARLIER WITH ONE OF THE POSTER'S ORIGINAL SCRIPTS AND IT DETECTED WHO HIT IT.
I do not believe I can emphasize that enough.