Script no work me is sad :c

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)
4 Likes

Be sure that you’re doing the addition from a server-sided script

2 Likes

i am dw
11111111111111111111111

2 Likes

and btw the particle effect doesn’t work because of this problem

1 Like

any errors or does it simply not run at all?

Have you tried adding print() everywhere to test where it breaks?

1 Like

there appears nothing 0 errors 0 warns

1 Like

Have you tried seeing if the function is running by printing a random message at the start? Maybe the event isn’t firing properly.

1 Like

Change this to Con.Value += 1 It’s better practise.

1 Like

did that already didn’t work
11111111111111111111111111111111111111

1 Like

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.

So please show your explorer

1 Like

server script
11111111111111111111111111111111

1 Like

Does help with the current problem.

1 Like

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.

1 Like

guess whos back at helping you? :smiley:

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

same thing for the tool script

4 Likes

This should work.

And so yes, the problem was the Players.LocalPlayer

Though the variables cha and lowertorso should be above plr becayse you are actually running tool.Parent twice which is redundant.

3 Likes

you’re the best dude
111111111111111111

1 Like

hey @deaconstjohn03 i will make a new topic so that u add text label in it if you want to , do you accept?

1 Like

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)
1 Like

i want when tool activated i made but no work :frowning:

1 Like

show me how you did it

30charlimit

1 Like