How do I use a Remote Event for two things?

Asked

Viewed 14 times

1

I’m trying to remake a power game on Roblox, I’m using an old Uncopylocked place as a base, and everything there is non-fe.

I wanted to use only one remote event for several codes (since they are all very similar), but I have no idea how to do that. This is an example script, it’s inside a button.

    local player = game.Players.LocalPlayer
    local Open = false
    function MouseClick()
        if Open == false then
            Open = true
            script.Parent.Text = "Learned"
            script.Parent:FindFirstChild("Flame Armor"):clone().Parent = player.Backpack -- Essa é a parte que eu usaria o remote
        end
        
    end
    script.Parent.MouseButton1Down:connect(MouseClick)

Could someone tell me what to send in the remote and what to put in the server-side script?

1 answer

0

Well... I came back! Yesterday I was talking to my friend about, until we came to a conclusion.

First we created an event in Replicatedstorage called "Give the stuff" (It was inside a folder) Then we create a folder in Replicatedstorage called Powers Then we put the event in Localscript and have it send the Power path to the server

evento = game.ReplicatedStorage.Events["Dar o bagulho"] -- O evento
player = game.Players.LocalPlayer
Open = false
function MouseClick()
    if Open == false then
        Open = true
        script.Parent.Text = "Learned"
        evento:FireServer(game.ReplicatedStorage:WaitForChild("Poderes").Phoenix) -- Envia o nome da pasta do poder para o servidor, nesse caso estamos fazendo com o Phoenix
    end
    
end
script.Parent.MouseButton1Down:connect(MouseClick)

Then in the server script we put this

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local itens = ReplicatedStorage.Poderes
local dador = game:GetService("ReplicatedStorage").Events["Dar o bagulho"]

local function poder(client, nome) -- Client é o LocalPlayer, nome é o caminho que passamos pra ele
    local tool = itens:FindFirstChild(tostring(nome)) -- Da o find first child no nome da pasta do poder

     if tool then -- Se tudo der certo/Se ele achar
        tool:FindFirstChild("Flame Armor"):Clone().Parent = client.Backpack -- Ele procura a skill dentro da pasta e te da
    end
end

dador.OnServerEvent:Connect(poder)

I hope I helped you, in case you had the same doubt I did :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.