Remote event failing to fire

I am writing a speedrun system for my game and I need this script to be functional for the remote event to fire and change a intvalue in the player it is supposed to continuously wait non stop until the speedrun boolvalue is enabled to run, but it does not run at all.

local value = game.Players.LocalPlayer.speedrun.Value
while not value do
	wait() 
end

while value do
	if value == true then
		game.ReplicatedStorage.speedrunaddcount:FireServer(game.Players.LocalPlayer)
	else
		return 
	end
end

Script responsible for assigning the name in correlation to the value of the intvalue

while true do
	wait()
	script.Parent.Text = game.Players.LocalPlayer.speedruncounter.Value
end

Server script that handles the remote (I already have a extremely powerful anticheat in place)


game.ReplicatedStorage.speedrunaddcount.OnServerEvent:Connect(function(player)
	wait(0.01)
	player.speedruncounter.Value = player.speedruncounter.Value+0.01
end)
1 Like

You should be adding the value on the server, or exploiters can just set their time to whatever they want or remove counting altogether. It would also be easier to program for you.

If you could show me the server code, I can implement it for you.

1 Like

doing while value do could be interpreted by the compiler as while value == true do

try this script and lmk if it works

local value = game.Players.LocalPlayer:WaitForChild("speedrun")

while value ~= nil do
	if value.Value == true then
		game.ReplicatedStorage.speedrunaddcount:FireServer(game.Players.LocalPlayer)
	else
		return 
	end
end
1 Like

Unfortunately no, it could be another error.

1 Like

I am aware of this fact, I have been programming for more than 5 years now, it is a simple (OPTIONAL) mode of the game that resets your stage to zero, disables datastore so you don’t lose your regular stage, waits for you to finish then saves it and puts it on the learderboard.

1 Like

For the server code, replace it with this:

game:GetService("Players").PlayerAdded:Connect(function(player)
	local speedrun = player:WaitForChild("speedrun")
	
	speedrun.Changed:Connect(function()
		while task.wait(0.1) and speedrun.Value do
			player.speedruncounter.Value += 0.01
		end
	end)
end)

Remove your LocalScript.

1 Like

Yes, which is why you should do it on the server. It’s simpler to implement anyway, so I’m not sure why you’ve opted to use RemoteEvents.

Good on you, I’m just trying to help.

1 Like

the intvalue is still unchanged.

1 Like

Are you changing the speedrun bool value on the server or client? Could you also show me the code that sets it to true/false?

1 Like

It is fired via a proximity prompt which redirects to a serverscript which handles the request.

![2023-12-14 22-01-59|video](upload://gDDOEnYNSop9s6GxhHW2XBYV86n.mp4)

local function speedrun(player)

	local gui = player.PlayerGui

	wait()
	player.speedrun.Value = true
	player:FindFirstChild("leaderstats").Stage.Value = 0
	gui:FindFirstChild("shop").Enabled = false
	gui:FindFirstChild("reprogress").Enabled = false
	gui.hm.Arame.Visible = false
	gui.hm.Frame.backwards.Visible = false
	gui.hm.Frame.forwards.Visible = false
	gui:FindFirstChild("position").Enabled = false
	gui:FindFirstChild("settings").Enabled = false
	gui:FindFirstChild("skip").Enabled = false
	gui:FindFirstChild("speedrungui").Enabled = true
	
end
1 Like

For a FireServer event, it automatically has a Player variable.

local value = game.Players.LocalPlayer.speedrun.Value
while not value do
	wait() 
end

while value do
	if value == true then
		game.ReplicatedStorage.speedrunaddcount:FireServer()
	else
		return 
	end
end

Script responsible for assigning the name in correlation to the value of the intvalue

while true do
	wait()
	script.Parent.Text = game.Players.LocalPlayer.speedruncounter.Value
end

Server script that handles the remote (I already have a extremely powerful anticheat in place)

game.ReplicatedStorage.speedrunaddcount.OnServerEvent:Connect(function(player)
	wait(0.01)
	player.speedruncounter.Value = player.speedruncounter.Value+0.01
end)

A.K.A. If you use :FireServer() from client, it automatically puts the player as the first option. OnServerEvent(Player)
SO if you do FireServer(player) it messes with the code, and it doesn’t work.

2 Likes

Could you tell me what this prints when the speedrun value changes?

game:GetService("Players").PlayerAdded:Connect(function(player)
	local speedrun = player:WaitForChild("speedrun")
	
	speedrun.Changed:Connect(function()
		print(speedrun.Value)
		while task.wait(0.1) and speedrun.Value do
			player.speedruncounter.Value += 0.01
		end
	end)
end)
1 Like

image

1 Like

Does it continue to print true? Also, are you setting speedruncounter.Value to 0 anywhere?

1 Like

@AmericanEagle124579 Please read over this before making any other large changes to your game.

1 Like

I even tried re tethering it to a remote and firing it with a simple while true do script but even that failed to work. I am just going to have to find another method to store time. or unless intvalues have some hidden property that continuiously sets any integer below 1 to 0.

1 Like

I put two and two together and realized that integer values can only store integers, an integer is literally a whole number, I don’t know why I didn’t realize this but here is the adjusted script for an integer value.

game:GetService("Players").PlayerAdded:Connect(function(player)
    local speedrun = player:WaitForChild("speedrun")
    local speedruncounter = player:WaitForChild("speedruncounter")

    speedrun.Changed:Connect(function()
        while wait(0.1) and speedrun.Value do
            local currentCounter = tonumber(speedruncounter.Value) or 0
            speedruncounter.Value = tostring(currentCounter + 0.01)
        end
    end)
end)

task.wait() is more accurate at tracking time, you should use it.

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