Why do u need seperate remote events?

what im trying to ask is: why do i need to add remote events into rs, heres an example

part.Touched:Connect(function()

it already makes a new remote event by me adding “Touch” into the script, so why do i need to make some manually?

1 Like

It is very unclear what you referring to specifically. A client side script could add a touch listener to a part and that event would fire on that client only. A server could add a listener and it would fire on the server only.

.Touched isn’t a remote event though?

I think your talking about the replication roblox already handles vs using remote events?

1 Like

sorry, i dont understand scripting much as im new, but how would u use a remoteevent, i need an example, if thats ok

But what exactly are you trying to do though first off

for example, to make a text change when a part is touched (ik u could easily script that but still)

Well is the text on the server your trying to change or on the client?

Because if its on the server no need for a remote event you can just used a .Touched event and then change the text on the server

1 Like

what if it was on the client, example for an obby game where the number changes when u touch a checkpoint

Well im guess you would have a leaderstats value “Stage” and when the player touches that part youu increment their Stage + 1, and then on the client you could just have it listen for when the value changes and then it’ll update accordingly

Server

part.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        local leaderstats = player:FindFirstChild("leaderstats")
        if leaderstats then
            local stage = leaderstats:FindFirstChild("Stage")
            if stage then
                stage.Value = stage.Value + 1
            end
        end
    end
end)

Client

local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")

local leaderstats = player:WaitForChild("leaderstats")
local stage = leaderstats:WaitForChild("Stage")

stage.Changed:Connect(function()
    textLabel.Text = "Stage: ".. stage.Value
end)
2 Likes

So sorry, but i don’t fully understand how it works, could someone explain it in details?

1 Like

I use it as a way to run a script remotely, hence the name.

So say I have a local Key detection script to check for certain keys being pressed. Instead of having to put whatever I want each key to run into that one detection script, I can use remote events to trigger them remotely. They also work as a way to detect an action locally but run a script on the server once that action has been determined

For example

local UIS = game:GetService("UserInputService")
local remote = (whatever remote you are using)

UIS.InputBegan:Connect(Function(input)
        If input.KeyCode == enum.KeyCode.G then
            remote:FireServer()
      end
end)

This script is very bare bones and isn’t perfect but it will connect to that remote event whenever the player hits the G key. I hope this clears it up a little?

1 Like

ohhhh i get it, thanks man i appreciate it

2 Likes

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