I’d like to transfer a script from local to server so everybody in the server can see it, but I don’t know how.
local player = game.Players.LocalPlayer.Name
local nameofplayer = game.Workspace:FindFirstChild(player) --Get the player in workspace
game.Workspace:FindFirstChild(player).Rank.Frame.Name1.TextColor3 = Color3.new(0, 255, 127)
game.Workspace:FindFirstChild(player).Rank.Frame.TextLabel.TextColor3 = Color3.new(0, 255, 127)
What exactly is this trying to accomplish? Is it a rank / different player tag over the player? You can use the game.Players.PlayerAdded event and get the player’s name from the Player instance passed in, at which point then you use this code that you supplied (the event and this code in a Server Script):
Now I’m no expert at coding, in fact I am rather new, but I think this is how it would work.
Then I recommend to use RemoteEvents for that, and have the LocalScript run a :FireServer on the RemoteEvent and pass in the player instance when the button is clicked. The script would contain the code to change it.
Again, I am no expert (I’m new) but I think that is how it would work, simplified.
Local Scripts only works with Local Player but if you trigger any Remote Event it is going to run a triggered function.
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local RemoteEvent = ReplicatedStorage.RemoteEvent
For the local side
local player = game.Players.LocalPlayer – This is local player
local detector = game.Workspace.ClickPart.ClickDetector – Find your part in Workspace or somewhere
RemoteEvent:FireServer() – Fires the server whenever a player clicks
print(“Activated the Event”)
For the normal script side:
RemoteEvent.OnServerEvent:Connect(function(plr) – plr is the activator
– What you code here is going to work for everyone in the server.
I am not an advanced scripter and tried my best to explain you. Hope you understand
Essentially, a RemoteEvent and a remote function kinda explain each other. A RemoteEvent causes a function in a remote (different) script, but it depends on what you Fire.
You basically need two parts. I’ll suit them for your need (kinda).
Assuming the RemoteEvent is game.ReplicatedStorage.RemoteEvent:
A game.ReplicatedStorage.RemoteEvent:FireServer() call somewhere in your LocalScript that occurs when the button is pressed. You can send in parameters inside the (), separated by commas, just like a function.
A game.ReplicatedStorage.OnServerEvent(function(user) end) in your Script. In the () next to function, you MUST put a parameter, as that is going to be the client that did the event (only need for Client->Server). Inside the function, you can put your code. You might not even need to pass anything in on the LocalScript since the user is put as a parameter when fired.
This can also work on reverse, you can have the server fire a single client or all clients using different functions, and the LocalScript would need a RemoteEvent.OnClientEvent in it.
I hope I’ve covered everything, but I could have left a gap, however I need to sleep due to it being late where I live. Good luck on your coding!
I have learned from here about 4 months ago: https://www.youtube.com/watch?v=RAP9OTrrep8
They are kinda confusing at first but you keep using them at different things you will get used to using RemoteEvent and RemoteFunctions