Hello, I fired a RemoteEvent to a main script in ServerScriptService, which is supposed to make the color of my part different. this is the script:
game.ReplicatedStorage.MakeRed.OnServerEvent:Connect(function()
local Player = game.Players.LocalPlayer
local Backpack = Player.Backpack
local Tool = Backpack:WaitForChild("LightStick"):WaitForChild("Handle")
Tool.Color = Color3.new(255, 0, 0)
end)
One problem was that you were trying to get the tool from the player instead of the player’s character. You would also have to pass the player in from the local script because you can’t get the local player from a server script using Player = game.Players.LocalPlayer. You would have to use the PlayerAdded function to get the local player from a server script.
Server Script:
game.ReplicatedStorage.MakeRed.OnServerEvent:Connect(function(player)
local Name = player.Name
local Player = workspace:WaitForChild(Name)
local Tool = Player:WaitForChild("LightStick"):WaitForChild("Handle")
Tool.Color = Color3.new(255, 0, 0)
end)
Local Script:
script.Parent.MouseButton1Click:Connect(function()
player = game.Players.LocalPlayer
game.ReplicatedStorage.MakeRed:FireServer(player)
end)
you’re supposed to have stuff inside of the :Fireserver event. And in the .Onserverevent for what you sent from the fire server. Also you can’t access player from server. Here’s how i’d do it.
local script:
script.Parent.MouseButton1Click:Connect(function()
local Player = game.Players.LocalPlayer
local Backpack = Player.Backpack
local Tool = Backpack:WaitForChild("LightStick")
local Handle = Tool:WaitForChild("Handle")
game.ReplicatedStorage.FixesFolder["MikeGFX's_Folder"].MakeRed:FireServer(Tool, Handle) -- this is what will be sent to the server.
end)
server script:
game.ReplicatedStorage.FixesFolder["MikeGFX's_Folder"].MakeRed.OnServerEvent:Connect(function(Player, Tool, Handle) -- PLAYER IS AUTOMATICLY THERE! DON'T REMOVE PLAYER!
Handle.BrickColor = BrickColor.new("Really red")
end)
also the reason why its mike gfx folder is because I have a game where I fix people’s errors xD.
Hope this helps.
also if you wanna see how this works then here: https://gyazo.com/52a23572b579783a31f3ef452af9a385
Doesn’t work, but no error catched up
in the output
this is the local script:
script.Parent.MouseButton1Click:Connect(function()
local Player = game.Players.LocalPlayer
local Backpack = Player.Backpack
local Tool = Backpack:WaitForChild("LightStick")
local Handle = Tool:WaitForChild("Handle")
game.ReplicatedStorage.FixesFolder["GamepassTools"].MakeRed:FireServer(Tool, Handle) -- this is what will be sent to the server.
end)
this is the script:
game.ReplicatedStorage.FixesFolder["GamepassTools"].MakeRed.OnServerEvent:Connect(function(Player, Tool, Handle) -- PLAYER IS AUTOMATICLY THERE! DON'T REMOVE PLAYER!
Handle.BrickColor = BrickColor.new("Really red")
end)
Oh, it’s because the tool wasn’t in the backpack. When tools are equipped they’re sent to the player’s character. I’ve gone ahead and fixed it. Here is the new LOCAL SCRIPT, NOT server script. Server script is the same.
script.Parent.MouseButton1Click:Connect(function()
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Backpack = Player.Backpack
local BackPackTool = Backpack:FindFirstChild("LightStick")
local CharTool = Character:FindFirstChild("LightStick")
if BackPackTool then -- if the tool is NOT equipped. Aka in the player's backpack
BackPackHandle = BackPackTool:FindFirstChild("Handle") -- this is a global variable. If it has an orange line underneath it then don't worry.
end
if CharTool then --- if the tool IS equipped. Aka in the player's character.
CharHandle = CharTool:FindFirstChild("Handle") -- this is a global variable. If it has an orange line underneath it then don't worry.
end
if BackPackTool then
game.ReplicatedStorage.FixesFolder["MikeGFX's_Folder"].MakeRed:FireServer(BackPackTool, BackPackHandle) -- this is what will be sent to the server.
elseif CharTool then -- if the tool isn't in the back pack then this will happen.
game.ReplicatedStorage.FixesFolder["MikeGFX's_Folder"].MakeRed:FireServer(CharTool, CharHandle)
end
end)
I can’t tell if this was mentioned, but a Remote fired from the client always, automatically, sends, Player as the first argument, so if you send one argument; it will be arg #2, by the time you start the Remote on the Server.
Note that the connected function (lines 6-12) will receive the Player who fired the event as its first parameter ( player ), along with any additional parameters passed from the FireServer() call.
game.ReplicatedStorage.FixesFolder["GamepassTools"].MakeRed.OnServerEvent:Connect(function(Player, Tool, Handle) -- PLAYER IS AUTOMATICLY THERE! DON'T REMOVE PLAYER!
Handle.BrickColor = BrickColor.new("Really red")
end)
local script:
script.Parent.MouseButton1Click:Connect(function()
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Backpack = Player.Backpack
local BackPackTool = Backpack:FindFirstChild("LightStick")
local CharTool = Character:FindFirstChild("LightStick")
if BackPackTool then
BackPackHandle = BackPackTool:FindFirstChild("Handle") -- this is a global variable. If it has an orange line underneath it then don't worry.
end
if CharTool then
CharHandle = CharTool:FindFirstChild("Handle") -- this is a global variable. If it has an orange line underneath it then don't worry.
end
if BackPackTool then
game.ReplicatedStorage.FixesFolder["GamepassTools"].MakeRed:FireServer(BackPackTool, BackPackHandle) -- this is what will be sent to the server.
elseif CharTool then -- if the tool isn't in the back pack then this will happen.
game.ReplicatedStorage.FixesFolder["GamepassTools"].MakeRed:FireServer(CharTool, CharHandle)
end
end)
the reason why I did this was because my folder had a speical character in it’s name. An apostrophe. Your folder does NOT have a special character. So do what I said above for all the things that said the other thing.
DO THIS!