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

BoolValue in player not getting detected by detect script?

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

✓ Accepted answer

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)

5 comments

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.

0

Also, I was wondering, would this work as the if statement -  p, li { white-space: pre-wrap; }

if plr.voted.Value == false then
0

And you are still using game.Players.LocalPlayer in line 5

0

my bad, fixed it

0

Yup, Worked! Thank you :D

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