Remote Event, cooldown value isn't working

Hey !

Alright, so i’m doing a system with a remote event to do a dash.
All arguments are given from a local script, to a script (with a remote event) and then to a module.

The problem is, the “Cooldown” value isn’t finded by the script, like it think that the value is in the humanoidRootPart, but it isn’t…

local script code

local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = game.Workspace:WaitForChild(Player.Name ,5)

local Events = game.ReplicatedStorage:WaitForChild("Events" ,5)
local Gui = Player:WaitForChild("PlayerGui" ,5)
local Cooldown = Player:WaitForChild("Cooldown" ,5)

if Events ~= nil and Gui ~= nil and Character ~= nil and Cooldown ~= nil then
	local DashEvent = Events:WaitForChild("Dash" ,5)
	local DashCooldown = Cooldown:WaitForChild("Dash" ,5)	
	local Toolbar = Gui:WaitForChild("Toolbar" ,5)
	local Humanoid = Character:WaitForChild("Humanoid" ,5)
	local Root = Character:WaitForChild("HumanoidRootPart" ,5)
	
	if  DashEvent ~= nil and Toolbar ~= nil and Humanoid ~= nil and Root ~= nil and DashCooldown ~= nil then
		local DashButton = Toolbar:WaitForChild("Dash" ,5)
		local Animator = Humanoid:WaitForChild("Animator" ,5)
		
		if  DashButton ~= nil and Animator ~= nil then

			local function DashUpdate()
				DashEvent:FireServer(Player, Animator, Root, DashCooldown)
			end
		
			UIS.InputBegan:Connect(function(key, processed)
				if key.UserInputType == Enum.UserInputType.Keyboard then
					if key.KeyCode == Enum.KeyCode.Space then
						DashUpdate()
					end
				end
			end)

			DashButton.MouseButton1Click:Connect(function()
				DashUpdate()
			end)
		end
	end
end

Script code

local Events = game.ReplicatedStorage:WaitForChild("Events" ,5)

if Events ~= nil then
	local AttackEvent = Events:WaitForChild("Attack" ,5)
	local AbilityEvent = Events:WaitForChild("Ability" ,5)
	local DashEvent = Events:WaitForChild("Dash" ,5)
	
	if AttackEvent ~= nil and AbilityEvent ~= nil and DashEvent ~= nil then
		
		DashEvent.OnServerEvent:Connect(function(Player, Animator, Root, DashCooldown)
			if DashCooldown.Value <= 0 then
				local Module = script:FindFirstChild("Dash")

				if Module ~= nil then
					local Function = require(Module)
					Function.Dashing(Player, Animator, Root, DashCooldown)
				end
			end
		end)
	end
end

Error

1 Like

You do not need to send the Player as an argument to the server. OnServerEvent automatically returns the player as the first argument.

So when you send the player as an argument you’re basically going to have 2 player arguments:

DashEvent.OnServerEvent:Connect(function(Player, PlayerThatYouSentAsAnArgument, Animator, Root, DashCooldown)

So in your local script just remove the player argument.

1 Like

Alright thanks, should i need to remove it in the script too or i let the “Player” as first argument ?

2 Likes

No, all you have to do is literally remove the Player argument from any :FireServer() call.

For example, your dash function ORIGINALLY looks like this:

DashEvent:FireServer(Player, Animator, Root, DashCooldown);

instead change it to:

DashEvent:FireServer(Animator, Root, DashCooldown)

Do the same thing for the other :FireServer calls you make. You don’t have to edit or remove anything else.

1 Like

Okay, thank you for helping it work now ^^

1 Like