I was trying to do is make it where the player can vote to regen the model. The voting thing should pop up and should have a timer. Here's the script I was working on.
map = game.Workspace.ship--Noob print("It works if this was printed") voted = {} votes = 0 time = 0 function onChatted(msg, recipient, speaker) if string.lower(string.sub(msg,1,10)) == "voteregen" then if playervoted(speaker.Name) == false then table.insert(voted, speaker.Name) print( speaker.Name .. " Inserted.") votes = votes + 1 if time == 0 then dotimer() end end end end function dotimer() for i = 1, 60 do time = time + 1 wait(1) end time = 0 end function playervoted(player) try = voted[player] if try ~= nil then return true end return false end function onPlayerEntered(newPlayer) newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end) end function respawn(model) backup = model:clone() model:remove() wait(2) model = backup:clone() model:makeJoints() model.Parent = game.Workspace end function startvote() if votes ~= 0 then if votes >= 5 and time < 60 then respawn(map) end end end game.Players.ChildAdded:connect(onPlayerEntered)
Thanks!
Ok I found the problem you should be check for a nil not false here is the code
local map = workspace.ship--Noob print("It works if this was printed") voted = {} votes = 0 time = 0 function onChatted(msg, recipient, speaker) if string.lower(string.sub(msg,1,10)) == "voteregen" then if playervoted(speaker.Name) == nil then table.insert(voted, speaker.Name) print( speaker.Name .. " Inserted.") votes = votes + 1 if time == 0 then dotimer() end end end end function dotimer() for i = 1, 60 do time = time + 1 wait(1) end time = 0 end function playervoted(player) try = voted[player] if try ~= nil then return true end return false end function onPlayerEntered(newPlayer) newPlayer.Chatted:Connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end) end function respawn(model) backup = model:clone() model:Destroy() wait(2) model = backup:clone() model:makeJoints() model.Parent = game.Workspace end function startvote() if votes ~= 0 then if votes >= 5 and time < 60 then respawn(map) end end end game.Players.PlayerAdded:Connect(onPlayerEntered)