Hello!
I made remote event which changes looks of part when fired.
I have multiple parts it is used in.
It is fired by clicking UI near the part, every part has UI assigned to itself.
Problem is that every part uses exact same singular remote event, because its all i need, and i dont know how i would need to script code to - best fore me - fire and affect only this part, whose GUI i click on, here’s bit of the script i use in the part:
local function changecolor()
script.Parent.Parent.BrickColor = BrickColor.black
end
game.ReplicatedStorage.Remotes.changecolorofpart.Event:Connect(changecolor)
and here’s part of the script i use in GUI, (by the way i use “Adornee” to place GUI near part):
local remote = game:GetService("ReplicatedStorage").Remotes
script.Parent.MouseButton1Click:Connect(function()
remote.changecolorofpart:Fire()
end)
how could i achieve something like i said at the start? Thanks for your time
you’ll need to pass some information from the GUI click event to the RemoteEvent so that the server knows which part to modify. One way to do this is to pass the part’s identifier (e.g., name or number) when firing the RemoteEvent.
Okay, that seems pretty good, thanks, but I have a question, could you show me how to do so? Before I tried to use “if” statement inside click script and it was something like “if part1 then” and it didn’t do anything at all ( I did scope part in workspace )
Before I start, I suggest you use Remote Event since you are communicating with server from client.
Here’s how you can adjust your script to include an identifier, such as the part’s name, and handle it on the server side:
Local Script:
local remote = game:GetService("ReplicatedStorage").Remotes.changecolorofpart
script.Parent.MouseButton1Click:Connect(function()
local partName = "Part1" -- Replace with the actual name of your part or any identifier
remote:FireServer(partName)
end)
"Part1" is the identifier so when you fire it to server the server script will handle it like this:
Server Script
local function changecolor(identifier)
if script.Parent:FindFirstChild(identifier) then
script.Parent:FindFirstChild(identifier).BrickColor = BrickColor.new("Black")
end
end
game:GetService("ReplicatedStorage").Remotes.changecolorofpart.OnServerEvent:Connect(function(player, identifier)
changecolor(identifier)
end)
That’s how you set it up on the workspace:
You can name the buttons or send the identifier the way you like (you get the idea lol)