Event keeps giving player

So I was making an event on when this event fires, it increases the time. But I keep receiving this error for some reason.


And it receives the player instead of the value. Here’s the script.

		event.OnServerEvent:Connect(function(player, timegiven)
			print(timegiven)
			timeinseconds += timegiven
		end)

What’s the code your are using to fire the event?
I suspect you are trying to provide the local player as an argument, when it’s actually provided automatically

I am using the command bar to fire the event.
Event:FireServer(30)

Testing the same setup, I see no reason why the second argument should be player as well.

Can you please provide a larger code sample for what you are running (copy paste it, not estimate)

local textlabel = script.Parent
local startTime = 130
local event = game.ReplicatedStorage.Events:WaitForChild("TimeIncrease")

local function startTimer(timeinseconds)
	for i=1, timeinseconds do
		script.Tick:Play()
		timeinseconds -= 1
		textlabel.Text = os.date('%M:%S', timeinseconds)
		event.OnServerEvent:Connect(function(player, timegiven)
			print(timegiven)
			timeinseconds += timegiven
		end)
		if timeinseconds < 120 then
			workspace.Ambience.Playing = true
		else
			workspace.Ambience.Playing = false
		end
		if timeinseconds == 0 then
			textlabel.Text = "ur cooked"
			return
		end
		task.wait(1)
	end
end

What about the client side more (the entire command that was run, not the abbreviated version you sent)

Also, with the code you sent just now, the for loop should be replaced with a while loop, and the OnServerEvent thing should be moved out of the loop:

local i = 1
event.OnServerEvent:Connect(function(player, timegiven)
	timeinseconds += timegiven
end)
while i <= timeinseconds do
	-- Code goes here
end
1 Like

Yeah, now I get how it works. Thanks!

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