so i have 4 buttons that i all want to do different things but i only want to use 1 remote event if possible. basically i've heard using multiple remote events is laggy for ur game so i'd prefer to only use one. is there any condition or something that i can use to check what button was pressed and based on that fire the remote event on a different script depending on what button i press, so let's say i press button 1 and then i only want it to fire on script 1 but if i press button 2 i only want it to fire on script 2. what's a condition that could help me separate the different scripts based on what button was pressed? and if there's no work around is having 4 remote events fine?
#how to use one remote event for different buttons
31 messages · Page 1 of 1 (latest)
Just use a server script lol
But if you really want/have to use a remote event for something like this, then you could pass a value based on which button was pressed
--Client Side
local RE = YOUR_REMOTE_EVENT
local button1 = YOUR_FIRST_BUTTON
local button2 = YOUR_SECOND_BUTTON
local button3 = YOUR_THIRD_BUTTON
button1.MouseButton1Click:Connect(function()
RE:FireServer("Button1")
end)
button2.MouseButton1Click:Connect(function()
RE:FireServer("Button2")
end)
button3.MouseButton1Click:Connect(function()
RE:FireServer("Button3")
end)
--Server Side
local RE = YOUR_REMOTE_EVENT
RE.OnServerEvent:Connect(function(plr, arg)
if arg == "Button1" then
print("Event Fired From Button 1")
elseif arg == "Button2" then
print("Event Fired From Button 2")
elseif arg == "Button3" then
print("Event Fired From Button 3")
end
end)
Hope you get the idea even tho I would recommend you just using a server script
i've tried but the script only runs once always
i have tried
but for some reason my script only works once
do u wanna see the script or
** You are now Level 5! **
no
I can't right now, I'm eating, but you can send it, I will look over it after
shhh
🤑
okay sure, so for a short description before sending this my scripts are for 4 buttons which change ur character. for my game i want to be able to change into 4 characters by button presses (2 are for male and 2 are for female).
game.Players.PlayerAdded:Connect(function(plr)
local f2Button = plr.PlayerGui:WaitForChild("genderChars").female2
-- getting button
f2Button.MouseButton1Click:Connect(function(female2)
local plrChar = plr.Character
local newChar = game.ServerStorage.charItems.characters.Female2:Clone()
-- getting player's char and new char
newChar.Name = plrChar.Name -- giving char the player's name
newChar.HumanoidRootPart.Position = Vector3.new(plrChar.HumanoidRootPart.Position) -- humanoidrootpart in same pos
plr.Character = newChar
newChar.Parent = game.Workspace
plrChar:Destroy()
-- replaces player's char with new char and puts it in workspace
end)
end)
that's 1 of 4 scripts
@prisma yarrow rn i'm testing with this using a remote event (hopefully u can help me laeter if server scripts are better) and i have a question. when checking for the arg let's say "Button1" if i were to add multiple args such as "Button1", "Cool" (example) when firing it from the clientside how would i go about checking if args == both of them?
ok
nvm i figured it out
hello there
** You are now Level 5! **
I was too late
Yea
yhea
yeah bro
teah