Remote Event not working

Local Script:

local player = game.Players.LocalPlayer
local plrHidden = player:WaitForChild("hiddenstats")

local timeText = script.Parent.LeftFrame2:WaitForChild("TimeText")

local seconds = plrHidden:WaitForChild("Seconds")
local minutes = plrHidden:WaitForChild("Minutes")

local RS = game:GetService("ReplicatedStorage")
local rent = RS.RemoteEvents:WaitForChild("RentAlert")
local rentGiver = RS.RemoteEvents:WaitForChild("RentGiver")


while true do 
	wait(0.5)
	timeText.Text = "0"..minutes.Value..":".."0"..seconds.Value
	seconds.Value += 1
	--print("Second + 1")
	if seconds.Value == 60 then
		--print("Rent")
		rent:FireServer(player)
		seconds.Value = 0
		minutes.Value += 1
	end
	if seconds.Value <= 9 and minutes.Value <=9 then
		timeText.Text = "0"..minutes.Value..":".."0"..seconds.Value
		--print("s & m less than 9")
	elseif seconds.Value >= 9 and minutes.Value >=9 then
		timeText.Text = minutes.Value..":"..seconds.Value
		--print("s & m more than 9")
	elseif seconds.Value >= 9 and minutes.Value <=9 then
		timeText.Text = "0"..minutes.Value..":"..seconds.Value
		--print("s more than 9 m less than 9")
	elseif seconds.Value <= 9 and minutes.Value >=9 then
		timeText.Text = minutes.Value..":".."0"..seconds.Value
		--print("m more than 9 s less than 9")
	end
	if minutes.Value == 24 then
		minutes.Value = 0
		seconds.Value = 0
		--print("ResetTime")
	end
end

rentGiver.OnClientEvent:Connect(function(money)
	print("given "..money.." to "..player.Name)
end)

Server Script:

local Players = game:GetService("Players")

local RS = game:GetService("ReplicatedStorage")
local remoteEvents = RS:WaitForChild("RemoteEvents")
local rentAlert = remoteEvents:WaitForChild("RentAlert")
local rentGiver = remoteEvents:WaitForChild("RentGiver")

function rentFired(player)
	local money = 1000
	print("rent Given".." to "..player.Name.." ("..money..")")
	rentGiver:FireClient(player, money)
end

rentAlert.OnServerEvent:Connect(rentFired)

I want the value from the server script to go to the client and the client to print the value it gets from the server to test some code. The server script works but it doesn’t make the rentGiver event fire for some reason. I’d like some help!

Thats because the while true do is blocking the thread by yielding indefinitely; simply put the

rentGiver.OnClientEvent:Connect(function(money)
	print("given "..money.." to "..player.Name)
end)

on top of the while true do

1 Like

also I noticed that you want to do some kind of 00:05:10 timer; instead of these, you can do this

timeText.Text = string.format("%02i:%02i", minutes.Value%60, seconds.Value%60)

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