Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

4 comments

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!

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.

0

:FireServer() on the remoteevent

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?

1 answer

✓ Accepted answer

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.

6 comments

0

I always find it tempting to downvote whenever someone has the word "upvote" in their answer.

1

ok but i put a lot of effort into this and did you even read my answer?

0

Shouldn't you save your down-votes for irrelevant/unhelpful answers?

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)

0

Cheers sir

0

Tee hee.

This discussion is preserved as it was. New answers, comments, and votes are closed.