when i eat food and fart the leaderstats “Consumed” IntValue doesn’t increase by 1 in value
script:
local tool = script.Parent
local sfx = tool.Handle:WaitForChild("SmokeSFX")
local players = game:GetService("Players")
local plr = players.LocalPlayer or players.PlayerAdded:Wait()
local leaderstats = plr:WaitForChild("leaderstats")
local Con = leaderstats:FindFirstChildWhichIsA("IntValue")
tool.Activated:Connect(function()
--instead of declaring variables at the start, we use them here to simplify
local cha = tool.Parent --the tool is in the character of the player, so Tool.Parent
local lowertorso =cha:WaitForChild("LowerTorso")
local smoke = Instance.new("Smoke")
smoke.Parent = lowertorso
smoke .Color = Color3.new(0,255,0)
sfx:Play()
smoke.Name = "Green"
smoke.Enabled = true
Con.Value = Con.Value + 1
wait(1)
smoke.Enabled = false -- lets wait the smoke disables for a smooth effect
game.Debris:AddItem(smoke, 2)
end)
I think I see the problem. Is this a server script or local script?
You say that you are going the addition on the server so you should be using a server script inside of the tool. But, you are using Players.LocalPlayer which is exclusive to Client sided scripts.
If this is a server script then Players.LocalPlayer will never be defined and Players.PlayerAdded:Wait() will give the next player that joins the game so I don’t think it’s the player you are looking for.
You can use Players:GetPlayerFromCharacter to get the player from the character when the tool is activated and then get leaderstats feom the player after that.
local tool = script.Parent
local sfx = tool.Handle:WaitForChild("SmokeSFX")
print("ah")
tool.Activated:Connect(function()
local plr = game.Players:GetPlayerFromCharacter(tool.Parent) --getting the player by the tool
local leaderstats = plr:WaitForChild("leaderstats")
local Con = leaderstats:FindFirstChildWhichIsA("IntValue")
--instead of declaring variables at the start, we use them here to simplify
local cha = tool.Parent --the tool is in the character of the player, so Tool.Parent
local lowertorso =cha:WaitForChild("Torso")
local smoke = Instance.new("Smoke")
smoke.Parent = lowertorso
smoke .Color = Color3.new(0,255,0)
sfx:Play()
smoke.Name = "Green"
smoke.Enabled = true
Con.Value = Con.Value + 1
wait(1)
smoke.Enabled = false -- lets wait the smoke disables for a smooth effect
game.Debris:AddItem(smoke, 2)
end)
make sure the leaderstats are created with a script and not a LocalScript
add a screengui in the tool, and add a textlabel in it
then in the tool, make a new LocalScript
local tool = script.Parent
local gui = tool:WaitForChild("ScreenGui")
local plr = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
--Make sure this is a local script
tool.Equipped:Connect(function()
gui.Parent = plr.PlayerGui --makes the text parent as the player gui, so this can be seen
end)
tool.Unequipped:Connect(function()
gui.Parent = tool --makes the text parent as the tool, so it wont be seen after unequipping the tool
end)