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

BoolValue in player not getting detected by detect script?

Asked by
acuaro 29
4 years ago

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!

1 answer

Log in to vote
0
Answered by
0msh 333 Moderation Voter
4 years ago
Edited 4 years ago

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)
0
Hmm, It seems like it should work, but I'm still getting an error. tried tweaking with the script, but that only made it worse. acuaro 29 — 4y
0
Also, I was wondering, would this work as the if statement -  p, li { white-space: pre-wrap; } if plr.voted.Value == false then acuaro 29 — 4y
0
And you are still using game.Players.LocalPlayer in line 5 acuaro 29 — 4y
0
my bad, fixed it 0msh 333 — 4y
0
Yup, Worked! Thank you :D acuaro 29 — 4y
Ad

Answer this question