___ Is not a valid member of Players."Player"?

I’m trying to make a script that detects if A Value In the player is = 1 then destroys a part

local clickDetector = game.Workspace.Spawn.ClickerPart.ClickDetector
local Stick = game.Workspace.Spawn["Meshes/stick"]

clickDetector.MouseClick:Connect(function()
	game.Workspace.Spawn["Meshes/stick"].Transparency = 0
	game.Workspace.Spawn.Wood.Transparency = 0
end)

if game.Players.LocalPlayer.ValueHammer.Value == 1 then
	Stick:Destroy()
end

Here is the script that makes the value

game.Players.PlayerAdded:Connect(function(player)
	local VelueHammer = Instance.new("IntValue", player)
	VelueHammer.Name = "ValueHammer"

But when i load up the game, This error message appears.
image

The problem may be that the value gets added after your if-statement checks for it. Try using WaitForChild to wait until the value gets added:

if game.Players.LocalPlayer:WaitForChild("ValueHammer").Value == 1 then
...
1 Like

do this instead

function init(player) 
	local VelueHammer = Instance.new("IntValue", player)
	VelueHammer.Name = "ValueHammer"
end
for i, player in next, game.Players:GetPlayers() do
        init(player) -- incase PlayerAdded didnt catch the previous players
end
game.Players.PlayerAdded:Connect(init)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.