This is the thing that I put off the most since I came back to Roblox. I KNOW what they're used for, communicating in between servers, clients and etc. I just don't know how to execute it. I also don't really get the different between remote events/functions.
Let me make a basic 'spawn kill brick' script. How would I turn this into FE compatible?
local plyr = game.Players.LocalPlayer local mouse = plyr:GetMouse() mouse.Button1Down:connect(function() local part = Instance.new("Part", workspace) part.Anchored = true part.Position = mouse.Hit.p -- part.Touched:connect(function(hit) if hit.Parent:findFirstChild("Humanoid") then hit.Parent.Humanoid:TakeDamage(5) end end) game.Debris:AddItem(part, 5) end)
Okay so remember to upvote and accept this if this helped you:
Taking your script you posted you wanted it, FE Compatible correct? Well remote events are basically telling the client or server to do something. So you need to create a new Remote event anywhere but in this case ReplicatedStorage.
local plyr = game.Players.LocalPlayer local mouse = plyr:GetMouse() mouse.Button1Down:connect(function() local part = Instance.new("Part", workspace) part.Anchored = true part.Position = mouse.Hit.p -- part.Touched:connect(function(hit) if hit.Parent:findFirstChild("Humanoid") then game.ReplicatedStorage.RemoteEvent:FireServer(hit.Parent.Humanoid,5) end end) game.Debris:AddItem(part, 5) end)
What I've done here is I fired the remote event with the correct arguments. But wait..? Nothing is going to happen because we never told the server what to do! So we need to create an OnServerEvent function.
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player,h,d) h:TakeDamage(d) end)
Remote events pass arguments (if needed) to the server. The first parameter on a server event will always be the player instance (because its from the client) so make sure you always put that down.