Hi, there I’m working on a script in which when an event is fired it should trigger a function. I Don’t know if OnClientEvent works in local scripts but it didn’t work. It would be great if I could have some help!
local Jump = script.Parent.Remotes:WaitForChild("Jump")
local function Jump()
if JumpEnabled --[[and math.abs(Board.Velocity.Y) < 5]] then
JumpEnabled = false
SetAnimation("Stop", {Animation = GetAnimation("BoardKick")})
SetAnimation("Stop", {Animation = GetAnimation("LeftTurn"), FadeTime = 0.5})
SetAnimation("Stop", {Animation = GetAnimation("RightTurn"), FadeTime = 0.5})
SetAnimation("Play", {Animation = GetAnimation("Ollie"), FadeTime = 0, Weight = 1, Speed = 4})
Board.StickyWheels = false
Board:ApplySpecificImpulse(Vector3.new(0, 45, 0))
OllieThrust.force = Vector3.new(0, 45, 0)
DidAction("Jump")
delay(0.1, function()
if OllieThrust then
OllieThrust.force = Vector3.new(0, 0, 0)
end
end)
else
Board.StickyWheels = true
end
end
Jump.OnClientEvent:Connect(Jump)
I think your problem here is that you have a function and a variable named the exact same thing. Rename your local Jump at the beginning. Here’s an example of the code you should use:
local JumpEvent = script.Parent.Remotes:WaitForChild("Jump")
local function Jump()
if JumpEnabled --[[and math.abs(Board.Velocity.Y) < 5]] then
JumpEnabled = false
SetAnimation("Stop", {Animation = GetAnimation("BoardKick")})
SetAnimation("Stop", {Animation = GetAnimation("LeftTurn"), FadeTime = 0.5})
SetAnimation("Stop", {Animation = GetAnimation("RightTurn"), FadeTime = 0.5})
SetAnimation("Play", {Animation = GetAnimation("Ollie"), FadeTime = 0, Weight = 1, Speed = 4})
Board.StickyWheels = false
Board:ApplySpecificImpulse(Vector3.new(0, 45, 0))
OllieThrust.force = Vector3.new(0, 45, 0)
DidAction("Jump")
delay(0.1, function()
if OllieThrust then
OllieThrust.force = Vector3.new(0, 0, 0)
end
end)
else
Board.StickyWheels = true
end
end
JumpEvent.OnClientEvent:Connect(Jump)
Also, make sure that you have a variable for JumpEnabled in the script. Is this the entire script?
Thanks for the help how ever the script didn’t work. Yes the jump enabled is a variable, I removed it but it still didn’t work. The script is located inside the player I don’t know if that has anything to go with it.
The script where the event is fired is from a local script in screen UI and the receiving code is in the local script. I know it would be better in the script but I need it in the local script to work.
If I’m understanding you correctly, are you saying that you use FireClient and receive OnClientEvent on two different local scripts? You can’t use FireClient on a local script, the client can not fire itself. If you want these two local scripts to interact with each other via an event, then you can use a BindableEvent: BindableEvent | Roblox Creator Documentation