How To Fire A RemoteEvent

I am trying to make a ball go to a part when the event is fired but I don’t know how to fire an event.

local ballEvent = game.ReplicatedStorage:WaitForChild("BallEvent")

local ball = game.Workspace:WaitForChild("Ball")
local particle = script.Parent.Attachment.ParticleEmitter

function onTouch()
	if (ball ~=nil) then
		particle:Clear()
	particle:Emit(10)
		wait(1)
		ball.Transparency = 1
		ball.Highlight.OutlineTransparency = 1
	end
end

ball.Touched:Connect(onTouch)
6 Likes

Use ballEvent:FireServer() and then connect to the event through another script e.x one from server script service.

Remote Events and Callbacks | Documentation - Roblox Creator Hub

3 Likes

personally I would use the deprecated fireServer because it’s funny (when exploiters try and hook it majority of them just hook the __namecall metamethod which requires them to use getnamecallmethod which majority of them only know about the “FireServer” namecall method and not the deprecated one which is “fireServer”) plus there is no downside to it because if you compare the deprecated method to the current one it returns the same

local Remote = Instance.new("RemoteEvent")

print(Remote.FireServer == Remote.fireServer) --> true
3 Likes

That did not work

local ballEvent = game.ReplicatedStorage:WaitForChild("BallEvent")

local ball = game.Workspace:WaitForChild("Ball")
local particle = script.Parent.Attachment.ParticleEmitter

function onTouch()
	if (ball ~=nil) then
		particle:Clear()
	particle:Emit(10)
		wait(1)
		ball.Transparency = 1
		ball.Highlight.OutlineTransparency = 1
		ballEvent:FireServer()
	end
end

ball.Touched:Connect(onTouch)
3 Likes

You have to define ballevent first. I would put the event in replicatedstorage.

edit: i didnt look at the original script lol, ignore this

3 Likes

Sorry it got cut off-------------

3 Likes

Deprecated means discontinued and can be removed at any time. Sure, it might be funny but the risk of it might stop existing or working one day would be pretty problematic. Plus all they have to do is to change one letter lol.

3 Likes

Can we see your server script for the event?

1 Like

That is the server script. It is in side a part

1 Like

I dont think that you can use :FireServer inside of a server script. Use bindable events for that instead.

1 Like

What is that------------------

1 Like

It is pretty much the same thing except you can fire other server scripts.

please correct me if i am wrong about that

Try doing this in the script you posted:

ballEvent:Fire()

On the other script:

ballEvent.Event:Connect(function()
--do cool stuff
end)

it said

 Event is not a valid member of RemoteEvent "ReplicatedStorage.BallEvent"

and

 Fire is not a valid member of RemoteEvent "ReplicatedStorage.BallEvent"

Change the remote event instance to a bindable event instead. Just remember to give it the same name so that you don’t need to update your variables again.

1 Like

What do you mean exactly?
When touched does it fire the function
or when touched, it fires a event to change that balls position

ballEvent.OnServerEvent:Connect(function()
--Blah blah blah
end)

Remote events are something that you want to fire either to clients or to servers.
if you fire it from a client script, you can fire it to a server
if you fire it from a server script, you can fire it to clients

if you wanna fire it between server to server, you need to make a client script that recieves and sends that

when you fire a event:

- to server
event:FireServer(put anything or none)

- to client
event:FireClient(put anything or none)

when you recieve a event

- server

event.OnServerEvent:Connect(function()

end)

- Client
event.OnClientEvent:Connect(function()

end)

Seeing you want to fire the event when the ball goes to a part, you do this

after ball touch function

ballEvent:FireServer(anything_or_none)

Or if im mistaken and you want the ball to go to a part when a event is fired

- from client 

ballEvent:FireServer()

- to your server script

ballEvent.OnServerEvent(function() 
Your code to move the ball
end)
1 Like

pretty sure you have to put bindable events in server storage not replicated sotrage

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