I need a money give code between the “-- log (money) give code” and “–”
(this code is from a tree that when your axe hits it, it gives you logs)
the script:
local Log = script.Parent
local hits = 5
local totalhits = 0
local SpareTree = game.ReplicatedStorage.Tree
local text = script.Parent.BillboardGui.TextLabel
local debounce = false
local maxnum = 5
Log.Touched:Connect(function(hit)
if debounce == false then
debounce = true
if hit.Parent.Name == "Axe" then
hits = hits + -1
text.Text = "Health: "..hits.."/"..maxnum
-- log (money) give code
--
if hits == totalhits then
if hits == totalhits then
text.Text = "Dead"
hits = 0
Log.Anchored = false
wait()
Log.Rotation = Vector3.new(45,0,0)
wait(3)
Log:Destroy()
local NewTree = SpareTree:Clone()
NewTree.Parent = workspace
text.Text = "Health: 5/5"
end
end
end
wait(1)
debounce = false
end
end)
local Log = script.Parent
local hits = 5
local totalhits = 0
local SpareTree = game.ReplicatedStorage.Tree
local text = script.Parent.BillboardGui.TextLabel
local debounce = false
local maxnum = 5
Log.Touched:Connect(function(hit)
if debounce == false then
debounce = true
if hit.Parent.Name == "Axe" then
hits = hits + -1
text.Text = "Health: "..hits.."/"..maxnum
-- log (money) give code
--
if hits == totalhits then
if hits == totalhits then
text.Text = "Dead"
hits = 0
Log.Anchored = false
wait()
Log.Rotation = Vector3.new(45,0,0)
wait(3)
Log:Destroy()
local NewTree = SpareTree:Clone()
NewTree.Parent = workspace
text.Text = "Health: 5/5"
end
end
end
wait(1)
debounce = false
end
end)
Ok, I assume that you have some sort of ownership value of the axe. If so you can locate the the player’s leaderstats folder and change their log(money) value.
the axe is a tool that the player uses to chop the tree. But I don’t know really what else to say about the “object/value that stores the owner of the axe”.
(not trying to be rude or anything)
You could get the Player instance from the parent of tool the as @Kaid3n22 said.
So the script should be something like this:
local Log = script.Parent
local hits = 5
local totalhits = 0
local SpareTree = game.ReplicatedStorage.Tree
local text = script.Parent.BillboardGui.TextLabel
local debounce = false
local maxnum = 5
Log.Touched:Connect(function(hit)
if debounce == false then
debounce = true
if hit.Parent.Name == "Axe" then
hits = hits + -1
text.Text = "Health: "..hits.."/"..maxnum
--// Money give.
local Player = game.Players:GetPlayerFromCharacter(hit.Parent.Parent) --// Grabs the player instanace from the character
local Leaderstats = Player:FindFirstChild("leaderstats") --// Finds the leaderstat folder in the player instance
Leaderstats.logs.Value += 1 --// Change the (1) to the amount you want to add to their logs(money)
--// Money give.
if hits == totalhits then
if hits == totalhits then
text.Text = "Dead"
hits = 0
Log.Anchored = false
wait()
Log.Rotation = Vector3.new(45,0,0)
wait(3)
Log:Destroy()
local NewTree = SpareTree:Clone()
NewTree.Parent = workspace
text.Text = "Health: 5/5"
end
end
end
wait(1)
debounce = false
end
end)
Please mark this as solution if this helps with your problem ! If it doesn’t please inform me if you receive any errors!