Make Function Not Affect Rest Of Script

  1. What do you want to achieve?
    I want my function to not affect the rest of my script.
  2. What is the issue?
    Currently my function has a wait in it, but I need it to not effect the script with the wait.
local Remote = game:GetService("ReplicatedStorage").Earth_Bender


function SetUpTimer(player)
	task.wait(1)
	player.Data.Debounces.EarthBenderDebounce.Value = false
end

Remote.OnServerInvoke = function(player, Info)
	if player:FindFirstChild("Data") and player.Data:FindFirstChild("Debounces") and player.Data.Debounces:FindFirstChild("EarthBenderDebounce") and player.Data.Debounces.EarthBenderDebounce.Value == true then
		return {"Player Can Not Use Ability!", "Player has tried to use the E Ability."}
	end
		if Info[1] == Enum.KeyCode.E then
			print("Player press E!")	
		player.Data.Debounces.EarthBenderDebounce.Value = true
		SetUpTimer(player)
		return {"Player has used the E Ability."}
	end
end

So, I need it to return, but also set up the function. It currently waits, then returns.

Edit: What if I make a table with the player in it and have a loop under all of this subtracting the debounce?

When A remote is called, the function won’t yield the whole script. It’ll launch a new thread and run the script asynchronously. I’d recommend changing that snippet right here from

Remote.OnServerInvoke = function(player, Info)

to

Remote.OnServerEvent:Connect(function(player, Info)

only if the issue persists.

Are you trying to remove the yield of the function? Yield means when a script has a wait() or some sort it can pause the rest of the script until it’s done.

Yes, I want the wait to not effect any other part of the script.

It’s a RemoteFunction, so that wouldn’t work.

You should probably try looking into coroutines then
https://developer.roblox.com/en-us/api-reference/lua-docs/coroutine

1 Like

alright, so instead use this, and see if it works.

task.spawn(SetUpTimer, player)
1 Like

Thanks! This worked out perfectly.

I will check out coroutines too.

I’d say that the task library is easier than coroutines, but both works the same.

Oh, alright, thank you so much!