Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make the color change for the server and other players instead of only local?

Asked by
ElBamino 153
3 years ago

Hey scriptinghelpers, how do I make this work for the server and other players. Right now it only changes color for the player with the tool, when I want it to change color for the whole server and other players. Thanks for the help in advance. I appreciate it. I'm only here to learn.

This is a LocalScript inside of a Handle(Part) inside of a Tool.

local player = nil
local character = nil
local handle = script.Parent
local tool = handle.Parent
local brickcolorvalue = game:GetService("ReplicatedStorage"):FindFirstChildWhichIsA("BrickColorValue")
function theplayer()
    if game:GetService("Players"):GetPlayerFromCharacter(tool.Parent) ~= nil then
        player = game:GetService("Players"):GetPlayerFromCharacter(tool.Parent)
        character = tool.Parent
    end
    if tool.Parent:IsA("Backpack") then
        player = tool.Parent.Parent
        character = tool.Parent.Parent.Character
    end
end
theplayer()
tool:GetPropertyChangedSignal("Parent"):Connect(theplayer)
function color()
    handle.BrickColor = brickcolorvalue.Value
end
color()
brickcolorvalue:GetPropertyChangedSignal("Value"):Connect(color)
1
LocalScripts only affect the client (ie. the player with the tool). You need to use a server 'Script' to affect the entire server. appxritixn 2235 — 3y
0
Yeah, I already tried using this as a "Script" before I posted this question and it didn't work. I don't get any output either. ElBamino 153 — 3y
1
No need to use remotes for this. Change it on the server and on the client, revert it to how it's suppose to be greatneil80 2647 — 3y
0
I don't really understand. I had to take a break from this script it was frustrating me. I'm going to continue testing now though, I'll get back to you guys. Sorry for the late response! ElBamino 153 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago

You need to use a RemoteEvent. Have a RemoteEvent named anything you like ready in ReplicatedStorage... in this case I'll just leave it as its default name "RemoteEvent".

function color()

game:GetService("ReplicatedStorage"):FindFirstChild("RemoteEvent"):FireServer(brickcolorvalue.Value,handle)

end

In another ServerScript, parented in ServerScriptService

game:GetService("ReplicatedStorage"):FindFirstChild("RemoteEvent").OnServerEvent:Connect(function(player,color,handle)

    handle.BrickColor = color

end)
Ad

Answer this question