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

How to change my tool color changing script to not be local?

Asked by 4 years ago

I made a script to change the color of a tool when you click a gui and it works, but its only for the user that clicked the button, so i changed it to a normal script but now it wont work, can someone help please? (its a script inside a gui which is inside the tool so i can make it pop up when you equip the tool)

local Handle = game.Players.LocalPlayer.Character.Glowstick:WaitForChild("Handle")
local RedButton = script.Parent:WaitForChild("RedButton")
local YellowButton = script.Parent:WaitForChild("YellowButton")
local OrangeButton = script.Parent:WaitForChild("OrangeButton")
local GreenButton = script.Parent:WaitForChild("GreenButton")
local BlueButton = script.Parent:WaitForChild("BlueButton")
local PurpleButton = script.Parent:WaitForChild("PurpleButton")

RedButton.MouseButton1Click:Connect(function()
     Handle.BrickColor = BrickColor.new("Really red")
    Handle.PointLight.Color = Color3.new(255, 0, 0)
end)

YellowButton.MouseButton1Click:Connect(function()
    Handle.BrickColor = BrickColor.new("New Yeller")
     Handle.PointLight.Color = Color3.new(255, 255, 0)
    Handle.Pointlight.Brightness = 2
end)

OrangeButton.MouseButton1Click:Connect(function()
    Handle.BrickColor = BrickColor.new("Deep orange")
    Handle.PointLight.Color = BrickColor.new("Deep orange").Color
    Handle.Pointlight.Brightness = 2
end)

GreenButton.MouseButton1Click:Connect(function()
    Handle.BrickColor = BrickColor.new("Lime green")
     Handle.PointLight.Color = Color3.new(0, 255, 0)
    Handle.Pointlight.Brightness = 2
end)

BlueButton.MouseButton1Click:Connect(function()
    Handle.BrickColor = BrickColor.new("Lapis")
    Handle.PointLight.Color = BrickColor.new("Lapis").Color
    Handle.Pointlight.Brightness = 3
end)

PurpleButton.MouseButton1Click:Connect(function()
    Handle.BrickColor = BrickColor.new("Magenta")
    Handle.PointLight.Color = Color3.new(170, 0, 170)
    Handle.Pointlight.Brightness = 2
end)
0
Try using a remote event for changing each color. sean_thecoolman 189 — 4y
0
got no clue how to do that lmao YourAverageMyth 45 — 4y
0
working on a solution for you! Kevin82951817 16 — 4y
0
alright finished if there are any issues comment! Kevin82951817 16 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I understand what you are trying to do. This script here only changes on the client and Roblox has a client-server model. Because of this, it only changes to the client. If you want to make changes on the server, you need to use a remote event

First, we will construct a server script in ServerScriptService! This will handle all the requests from the client to the server.

local replicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = Instance.new("RemoteEvent")
remoteEvent.Name = "ChangeToolColor"
remoteEvent.Parent = replicatedStorage 

remoteEvent.OnServerEvent:Connect(function(plr,brickColor,pointLightColor,pointlightBright)
    local Handle = plr.Character:FindFirstChild("Glowstick").Handle
    if Handle then
        Handle.BrickColor = brickColor
        Handle.PointLight.Color = pointLightColor
        if pointlightBright then -- It appears that one of your buttons does not have a brightness so we will make an if statement to make sure it exists.
            Handle.PointLight.Brightness = pointlightBright
        end
    end
end)

Great! The remote event listener is completed. We will now work on the local script where we will request the server to change the item.

local replicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = replicatedStorage:WaitForChild("ChangeToolColor")

local RedButton = script.Parent:WaitForChild("RedButton")
local YellowButton = script.Parent:WaitForChild("YellowButton")
local OrangeButton = script.Parent:WaitForChild("OrangeButton")
local GreenButton = script.Parent:WaitForChild("GreenButton")
local BlueButton = script.Parent:WaitForChild("BlueButton")
local PurpleButton = script.Parent:WaitForChild("PurpleButton")

RedButton.MouseButton1Click:Connect(function()
    remoteEvent:FireServer(BrickColor.new("Really red"),Color3.new(255, 0, 0),nil)
end)

YellowButton.MouseButton1Click:Connect(function()
    remoteEvent:FireServer(BrickColor.new("New Yeller"),Color3.new(255, 255, 0),2)
end)

OrangeButton.MouseButton1Click:Connect(function()
    remoteEvent:FireServer(BrickColor.new("Deep orange"),BrickColor.new("Deep orange").Color,2)
end)

GreenButton.MouseButton1Click:Connect(function()
    remoteEvent:FireServer(BrickColor.new("Lime green"), Color3.new(0, 255, 0),2)
end)

BlueButton.MouseButton1Click:Connect(function()
    remoteEvent:FireServer(BrickColor.new("Lapis"),BrickColor.new("Lapis").Color,3)
end)

PurpleButton.MouseButton1Click:Connect(function()
    remoteEvent:FireServer(BrickColor.new("Magenta"),Color3.new(170, 0, 170),2)
end)

If there are any issues, let me know. I also highly suggest you check out the resources I will link below so you can get a better understanding of the client-server model and the remote functions and events.

https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events https://developer.roblox.com/en-us/articles/Roblox-Client-Server-Model

Enjoy your day!

Ad

Answer this question