Help with local script

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)

The OnClientEvent event is fired whenever a server script either calls FireClient() or FireAllClients() you can learn more here:

local Jump = script.Parent.Remotes:WaitForChild("Jump")

Jump.OnClientEvent:Connect(function()
	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)

You declared “Jump” twice so the 2nd declaration ended up overriding the 1st.

1 Like

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?

1 Like

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.

Can you send a screenshot of the script and its contents?

sorry let me get back to you tomorrow!

1 Like

Sorry for the late reply Here’s a screenshot of the script.

And a bigger screenshot of the script.

function MoveStateChanged(NewState, OldState)
	if not JumpEnabled then
		--if not airray then
		EnterAirState(false)
		--end
	end
	if NewState == Enum.MoveState.AirFree then
		if airray then
			--if #script.Parent.Parent["Left Rear"]:GetTouchingParts() < 1 or #script.Parent.Parent["Right Rear"]:GetTouchingParts() < 1  then 
			EnterAirState(true)
		end
	elseif NewState == Enum.MoveState.Pushing then
		EnterPushingState()
	elseif NewState == Enum.MoveState.Coasting then
		EnterCoastingState()
	elseif NewState == Enum.MoveState.Stopping then
		EnterStoppingState()
	end
end

function MakeOllieThrust()	
	OllieThrust = Instance.new("BodyThrust")
	OllieThrust.Name = "OllieThrust"
	OllieThrust.force = Vector3.new(0, 0, 0)
	OllieThrust.location = Vector3.new(0, 0, -30)
	OllieThrust.Parent = Board
end

function MakeGyro()	
	Gyro = Instance.new("BodyGyro")
	Gyro.Name = "SkateboardGyro"
	Gyro.maxTorque = Vector3.new(0, 0, 0)
	Gyro.P = 300--modified from 200 for stability
	Gyro.D = 300
	Gyro.Parent = Torso
end


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)


And, just to make sure, you are calling the RemoteEvent from the server, correct?

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

2 Likes