I was working on my game, where there is a voting feature. I want to check weather the player voted so they can't vote again so I created a bool value inside the player through my GM script right here
game.Players.PlayerAdded:Connect(function(player) local boolValue = Instance.new("BoolValue", player) boolValue.Name = "voted" boolValue.Value = false end)
This works, but what dose not is the detector script. The detector script is a Script inside the voting platforms; the code is below.
local bar = script.Parent.bar1.bar script.Parent.Touched:Connect(function(plr) if game.Players.LocalPlayer.voted.Value == false then bar.Size = bar.Size + Vector3.new(0, 1.44, 0) game.Workspace.voted.Value = true end end)
The console only says that something is wrong at line 4 (if game.Players etc). But when I tried trouble shooting it, nothing changed. I'm really confused and Hope someone can help. Thank you in advance!
this should be inside of ServerScriptService, which is your first script:
game.Players.PlayerAdded:Connect(function(player) local boolValue = Instance.new("BoolValue", player) boolValue.Name = "voted" boolValue.Value = false end)
then you said you have a script inside the voting platform with an error. You can't use
game.Players.LocalPlayer
inside of a script.
Use GetPlayerFromCharacter because you're trying to figure out which player touched something
local bar = script.Parent.bar1.bar local p = game:GetService("Players") script.Parent.Touched:Connect(function(char) local plr = p:GetPlayerFromCharacter(char) if plr.voted.Value == false then bar.Size = bar.Size + Vector3.new(0, 1.44, 0) game.Workspace.voted.Value = true end end)