There is a pretty simple way to do this. Now as your question is
non-constructive
I like to help everyone!
First, we have to setup the leaderstats. This can be done with a simple script:
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Value = 500
cash.Parnet = leaderstats
end)
Next, we have to setup the main script so the player can buy the house:
local detector = script.Parent
local price = 500
local owned = false
detector.Touched:Connect(function(hit)
if owned == false then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player and player:FindFirstChild("leaderstats") and player.leaderstats:FindFirstChild("Cash") then
local cash = player.leaderstats.Cash
if cash.Value >= price then
cash.Value = cash.Value - price
owned = true
print(player.Name.." now owns a house!")
end
end
end
end)
I hoped this helped! If some code doesn't work just let me know. And next time, try to be more constructive with your question.
5 comments
Whats the error??
i dont know but it says i got one on line 7
can you show the output?
its on line 4 but on this it makes it say line 7 for me
With a click detector, you can just use (player) you don't use (hit) then you can say something like print(player.Name) and it would print the player's name that clicked it.