i really dont see anything wrong here, but for some reason i get this error: Workspace.COMPOOTER.Script:7: attempt to index nil with 'points’
i feel like im stupid and messed up something but i’ve tried anything, i’ve checked the names, maybe i misstyped, i dont know! and i use the same script for other scripts too, where is my error?
script.Parent.Touched:Connect(function(player)
local points1 = player:FindFirstChild("leaderstats")
local ComV = script.Parent.Value
points1.points.Value = ComV.Value + points1.points.Value
end)
When the touched event is connected to a function, the Instance it returns will be the part that activated the event (such as a part of the Character model) and not the player object.
In order to access the player object, I’d reccomend using the :GetPlayerFromCharacter() method of the Players Service on part.Parent (aka what could be the player’s Character model) before looking for the player’s leaderstats folder:
local Players = game:GetService("Players")
script.Parent.Touched:Connect(function(part)
local player = Players:GetPlayerFromCharacter(part.Parent)
if player then
local leaderstats = player:FindFirstChild("leaderstats")
-- Continue
--[[ Make sure to check if the leaderstats folder and subsequently the
"points" Instance exists in additional "if then" statement to prevent
any other errors from occurring --]]
end
end)
I have to do something rn but the problem here is that you didn’t call the player from the character. You can look on the devforum for how.
script.parent.touched;connect(function ()
If hit.parent:findfirstchild("humanoid") then
Local player = game:getplayerfromcharacter(hit.parent)
--continue with code
End
End)
Hope this helped. Sorry if rushed
Edit: this is like the post above by @StrongBigeMan9