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

leaderstats is not a valid member of MeshPart ?

local PartTouch = false

game.Workspace.Part.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then if test == false then local keys = hit.leaderstats.keys keys.Value = keys.Value + 1 end end end)

but it says in output

leaderstats is not a valid member of MeshPart "Workspace.abdulw12.RightLowerLeg

1 answer

✓ Accepted answer

The "hit" variable returns the part that touched the brick.

replace this:

hit.leaderstats.keys keys.Value = keys.Value + 1

with this:

game:GetService("Players"):GetPlayerFromCharacter(hit.Parent).leaderstats.keys keys.Value = keys.Value + 1

oh wait I forgor to explain ????????

the .Touched event returns the part that touched the brick.

hit.Parent is the Character if a player had touched the brick.

game:GetService("Players") is just a safer version of game.Players

:GetPlayerFromCharacter(hit.Parent) gets the actual player object parented to game.Players.

hope that helped!!

2 comments

0

To add to this answer: note that a full script would make sure that there is a player returned from GetPlayerFromCharacter (in case a random object hit the button instead of a player)

0

im lazy i just pcall it

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