i tried this but it is coming invalid
game.ReplicatedStorage.RemoteEvent:FireServer()
and on the other script i used
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(hit) --Stuff here end)
You can't.
FireServer only works in LocalScripts, which can only be ran on the local client (that's you!), while the server is where the game pretty much operates on a grand scale.
You're trying to use a RemoteEvent which is used to communicate between Server and Client. If you want to fire an event to communicate through two Scripts with the same type, use BindableEvents instead. (Works like a RemoteEvent, but only works on one side you're using)
Link to API reference of BindableEvent
Your scripts after replacing the remote to BindableEvent instead
--You don't need to put this in ReplicatedStorage as long as the script sees this --The BindableEvent here is named BindableEvent btw game.ReplicatedStorage.BindableEvent:Fire()
Other script:
game.ReplicatedStorage.BindableEvent.Event:Connect(function(hit) --Stuff here end)
Bonus: If you want it to work in a Script, here it is
--Remember to create a BindableEvent and rename it in ReplicatedStorage local function FireServer(...) game.ReplicatedStorage.BindableEvent:Fire(...) end FireServer()
Other script
local bind = game.ReplicatedStorage.BindableEvent bind = setmetatable({ OnServerEvent = bind.Event }, {__index = bind}) bind.OnServerEvent:Connect(function(hit) --Stuff here end)
Hello, in order to use FireServer
, you will need to fire it via a LocalScript, which is used to transfer stuffs or happen things which would only happen in server-sided, for example a player would spawn a part by a TextButton, you would need a RemoteEvent for that using the FireServer for the part to be visible on server.