So i wanted to make a script that when a player touches a part the players points would drop down but it gives me an error which says leaderstats is not a valid member of Model.Also the script is inside that part
You are looking for leaderstats in their character, use game.Players:GetPlayerFromCharacter()
You’re getting the character and checking the leaderstats, you need to get the player, Use
game:GetService("Players"):GetPlayerFromCharacter(lean.Parent)
And get the leaderstats from there
2 Likes
I guess leaderstats must be in player dude.
1 Like
The probem is that the leaderstats is a child of the player object, not the character. You need to get the player from the touched character. Here’s how to use the function to get the player.
1 Like
local part = script.Parent
local Players = game:GetService("Players")
local db = false
local Delay = 1 -- how long to wait between each touch
part.Touched:Connect(function(lean)
if lean.Parent:FindFirstChild("Humanoid") == nil then return end
if db == false then
db = true
local player = Players:GetPlayerFromCharacter(lean.Parent)
local leaderstats = player.leaderstats
local Points = leaderstats.Points
Points.Value -=5
task.wait(Delay)
db = false
end
end)
I suggest putting a debounce if you want it to not subtract 5 from you too quickly.