Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

I'm still soo confused on how to use remove events/functions. ??

Asked by
Infocus 144
4 years ago

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)
0
You should see the wiki page for it, https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events it talks about the difference about remote events/functions and how to use them! moo1210 587 — 4y
0
Sir I did read about that, I forgot to mention it on the post. I posted here because I still really don't understand how to execute it. Infocus 144 — 4y
0
:FireServer() on the remoteevent moo1210 587 — 4y
0
Can you elaborate dude? Because the dev. link is showing me to put my code in a script then use local to fire it. How do I get the localPlayer in the script? Infocus 144 — 4y

1 answer

Log in to vote
2
Answered by
p0vd 207 Moderation Voter
4 years ago
Edited 4 years ago

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.

0
I always find it tempting to downvote whenever someone has the word "upvote" in their answer. ScuffedAI 435 — 4y
1
ok but i put a lot of effort into this and did you even read my answer? p0vd 207 — 4y
0
Shouldn't you save your down-votes for irrelevant/unhelpful answers? Optikk 499 — 4y
0
p0vd explanation is right.. Imagine you're the client, and you want to get inside of the server but you can't. You need to have access to the BIG Gate to get inside of the server. Just imagine the Gate is like a Security. (Client) >> (GATE) >> (SERVER) TankArgie_DEV 0 — 4y
View all comments (2 more)
0
Cheers sir Infocus 144 — 4y
0
Tee hee. TankArgie_DEV 0 — 4y
Ad

Answer this question