As far as your script goes, basically a lot of things went wrong. For example, I dont remember leaderstats existing in the character(hit.Parent), but rather the player of the character; So you should have searched for leadersats in the player of the character instead(you did put leaderstats in the player, right?). In addition, the way you checked for the money(player.leaderstats.Bucks.Value > 10) would be saying that you had to have over 10 dollars(e.g $10.1) to purchase the sword worth $10. The appropriate way to check for if the player has equal to or over $10 would be to use ">=" instead of ">". I made a rough edit of your code, which should work; though i cant assure you that:
local function getPlayerFromCharacter(character)
for _, player in pairs(game:GetService("Players"):GetPlayers()) do
if player.Character == character then
return player
end
end
end
script.Parent.Touched:Connect(function(hit)
if hit.Parent.Humanoid then
print("it was a player")
local player = getPlayerFromCharacter(hit.Parent)
if player.leaderstats.Bucks.Value < 10 then
print("u broke boi")
elseif player.leaderstats.Bucks.Value >= 10 then
print("purchasing sword...")
local sword = game.ReplicatedStorage.ClassicSword:Clone()
sword.Parent = player.BackPack
print("sword acquired")
player.leaderstats.Bucks.Value = hit.Parent.leaderstats.Bucks.Value - 10
print("sword has been paid for")
end
end
end)
im sorry im rusty at this
6 comments
can you indent the code and use the little lua icon to make it easier to read please
the lua icon that shows up when you're editing your post*
yes pls format
also purchase is spelt wrong
how much bucks u have?
50