I tried to make it like if the player collects an item, the player can’t collect it again
but this is happen, can someone help?
20:25:18.339 Players.crucewtemenrizky.PlayerGui.Scripts.LocalScript:5: attempt to index nil with 'Value' - Client - LocalScript:5
local script
local Player = game.Players.LocalPlayer
local CollectEvent = game.ReplicatedStorage.CollectEvent
CollectEvent.OnClientEvent:Connect(function(pl, iscollected)
if iscollected.Value == false then
iscollected.Value = true
Player.HeadsFound.Value +=1
else
print("HeadsFound")
end
end)
local iscollected = script:WaitForChild("IsCollected")
local collectEvent = game.ReplicatedStorage.CollectEvent
script.Parent.Triggered:Connect(function(player)
collectEvent:FireClient(player, iscollected)
end)
i think the iscollected is inside ServerScriptService and since the client cant see in there, what they see is nil in place of iscollected
also, setting iscollected to true and checking it in a local script is a security risk, as a hacker could set it to false again, whereas if you set it to true and check it on the server they will have no access to it. this would also fix your bug
This is correct. The problem is in your client script, where there is the pl argument, but the server script is fine.
All you need to do is take that out.
For example:
Your original script:
local Player = game.Players.LocalPlayer
local CollectEvent = game.ReplicatedStorage.CollectEvent
CollectEvent.OnClientEvent:Connect(function(pl, iscollected)
if iscollected.Value == false then
iscollected.Value = true
Player.HeadsFound.Value +=1
else
print("HeadsFound")
end
end)
A fixed version:
local Player = game.Players.LocalPlayer
local CollectEvent = game.ReplicatedStorage.CollectEvent
CollectEvent.OnClientEvent:Connect(function(iscollected)
if iscollected.Value == false then
iscollected.Value = true
Player.HeadsFound.Value +=1
else
print("HeadsFound")
end
end)