Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

leaderstats is not a valid member of MeshPart ?

Asked by 3 years ago

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

Log in to vote
2
Answered by 3 years ago
Edited 3 years ago

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!!

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) chess123mate 5873 — 3y
0
im lazy i just pcall it Qwertoony 70 — 3y
Ad

Answer this question