I want to make a part have a proximity prompt that gives me a tool when used. But I want it to be purchased with a leaderstat. For example, Buy Sword for 100 Points. The points would then be deducted from my leaderstats.
I just cannot get it to work. My points don’t get deducted, nor do I get the tool. There are no errors either.
local proximityPrompt = script.Parent
local purchase = game.ReplicatedStorage.Tools.ClassicSword
proximityPrompt.Triggered:Connect(function(player)
local points = player.leaderstats:FindFirstChild("Points")
if points.Value >= 100 then
points.Value = points.Value - 100
local clone = purchase:Clone()
clone.Parent = player.Backpack
end
end)
I have asked people on discord servers, Youtube videos, and even ChatGPT but none of these have helped.
Get 100 points then buy the sword, you don’t have enough points. Your code works fine after all
For the Points print, print Points.Value instead to see how much points you have
Are the points being added by a Script as well? There could be a mismatch between what the client believes and what the server knows if a LocalScript is handling the point provisions. You say you had more than 100 points, so I’m imagining those were awarded by the client.
That’d be acceptable if you switched to the Server mode of Play Solo. I wouldn’t trust changing it in the default Client mode. That’s assuming you’re doing this while the game is running.
Normal Scripts can change points, the command bar in Server mode can change points, and the F9 Server command bar (in an actual roblox game server you have permissions for) can change points. Make sure you’re targeting the right instance and not a template or something like that.
I’d like to provide some exact code and steps to try out but something came up and I won’t be online until a few hours later. I hope someone else can guide you.