Need help with a counter

Am I doing something wrong here? I want this counter to go up by one each time the “enemykilled” RemoteEvent is fired. It’s as if it only fires once, though, the counter only remaining at 1 no matter how many times I fire it afterwards.

local rs = game:GetService("ReplicatedStorage")
local enemykilled = rs:WaitForChild("enemykilled")

local soulcounter = 0
local soulslabel = script.Parent

enemykilled.OnClientEvent:Connect(function(player)
	soulslabel.Text = "souls: ".. soulcounter + 1
end)

I got no clue what’s going on. Please help!

you forgot to increment the value soul counter

its because youre not increasing the soulcounter variable so the script will always try to do 0 + 1

local rs = game:GetService("ReplicatedStorage")
local enemykilled = rs:WaitForChild("enemykilled")

local soulcounter = 0
local soulslabel = script.Parent

enemykilled.OnClientEvent:Connect(function(player)
    soulcounter += 1 --// add 1 to the variable
	soulslabel.Text = "souls: ".. soulcounter --// no need for the +1 since we already added
end)
3 Likes

try that

local rs = game:GetService("ReplicatedStorage")
local enemykilled = rs:WaitForChild("enemykilled")

local soulcounter = 0
local soulslabel = script.Parent

enemykilled.OnClientEvent:Connect(function(player)
soulcounter += 1
	soulslabel.Text = "souls: ".. soulcounter
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.