hello i have this issue with my code where when a player destroys a tree a proximity prompt shows up to collect the wood but when the player holds E and finishes the prompt then nothing happens.
here is my code: (do note that im new to coding)
local dataservice = game:GetService("DataStoreService")
local leaderstats = dataservice.leaderstats
local wood = leaderstats.Wood
script.Parent.Triggered:Connect(function(plr)
script.Parent.Parent:Destroy()
wood.Value = wood.Value + 1
end)
here is my leaderstats script:
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Wood = Instance.new("IntValue")
Wood.Name = "Wood"
Wood.Parent = leaderstats
local Stone = Instance.new("IntValue")
Stone.Name = "Stone"
Stone.Parent = leaderstats
local Level = Instance.new("IntValue")
Level.Name = "Level"
Level.Parent = leaderstats
end)
Here is a picture of where my stuff is parented to.
im pretty sure he means that basically the script is being destroyed before the value can change, actually im pretty sure that is the reason why the value isnt changing
local dataservice = game:GetService("DataStoreService")
local leaderstats = dataservice.leaderstats
local wood = leaderstats.Wood
script.Parent.Triggered:Connect(function(plr)
wood.Value = wood.Value + 1
if wood.Value == wood.Value + 1 then
script.Parent.Parent:Destroy()
end
end)
and leaderstat:
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Wood = Instance.new("IntValue")
Wood.Name = "Wood"
Wood.Parent = leaderstats
local Stone = Instance.new("IntValue")
Stone.Name = "Stone"
Stone.Parent = leaderstats
local Level = Instance.new("IntValue")
Level.Name = "Level"
Level.Parent = leaderstats
Wood.Value = 0
Stone.Value = 0
Level.Value = 0
end)
Lol, missed it first time round! The leaderstats folder is parented to the player, but the function connects to a leaderstats in the DatastoreService.
You will need to use player service and find the player.
local dataservice = game:GetService(“DataStoreService”)
local leaderstats = dataservice.leaderstats
local wood = leaderstats.Wood
remove that
and theres a extra end hanging there which causes the error that happened because you didnt remove the end for if wood.Value == wood.Value + 1 then