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

Why is my BrickColorValue not changing the BrickColor of my tools handle?

Asked by
ElBamino 153
3 years ago
Edited 3 years ago

Hey scriptinghelpers, I'm working on a script that changes the BrickColor of my tools handle. I was using something similar in a local script but, the problem with that was it didn't change the color for other than the player holding the tool. I don't really know how else to word this question, sorry about that. I need the color to be visible to all players to know who touched it last.

I'm considering using ServerScriptStorage but, I don't know how I would find the player who has the tool. There would be 10 players if my server was full.

This is a script inside of a handle inside of a tool. BrickColorValue in ReplicatedStorage (this is so that I can read always read it since I don't know how to find the player who has the tool, tool name is "Ball")

local value = game.ReplicatedStorage:FindFirstChild("BrickColorValue")
value.Changed:Connect(function(new)
    script.Parent.BrickColor = value.Value
end)

My other script was a local script inside of the tool.

while true do
    wait(1)
    if game.ReplicatedStorage.StringValue.Value == "Equipped" then
        script.Parent.Handle.BrickColor = game.ReplicatedStorage.BrickColorValue.Value--this value is constantly changing to whoever touched it last going by there team color I have a separate script for this

Thanks for the help in advance! I'm just kinda confused, I actually wasn't going to ask this question since it's so simple. Just can't seem to figure it because, everything looks perfect to me. In other ways I know it would work but, it's not.

1 answer

Log in to vote
1
Answered by
NGC4637 602 Moderation Voter
3 years ago

ok so uh heres what you can do to reference the local player and its character in a server script inside a tool's handle.

local player = nil -- for now it is nil
local character = nil
local handle = script.Parent
local tool = handle.Parent
local BrickColor = game:GetService("ReplicatedStorage"):FindFirstChildWhichIsA("BrickColorValue")  -- ima just search it by its class name.

function playerref()
    if game:GetService("Players"):GetPlayerFromCharacter(tool.Parent) ~= nil then -- in case the weapon is equipped
        player = game:GetService("Players"):GetPlayerFromCharacter(tool.Parent)
        character = tool.Parent
    end
    if tool.Parent:IsA("Backpack") then -- yes, backpack is a separate class 
        player = tool.Parent.Parent -- in case the weapon is not equipped
        character = tool.Parent.Parent.Character
    end 
end

playerref() -- do the function once

tool:GetPropertyChangedSignal("Parent"):Connect(playerref) -- do it everytime the tool's parent changes, to prevent some bugs (?)

function colorchange()
    handle.BrickColor = BrickColor.Value
end

colorchange()

BrickColor:GetPropertyChangedSignal("Value"):Connect(colorchange)
0
Hey there (Again thanks for answering my questions. I really appreciate it sorry for the late response again), so I just tested this one out. It's not changing the color of the handle. There's no errors in output either. I'm going to keep testing some more, try some stuff out see if I can get it to work. Let me know though if you find something before me (I'm no pro so you probably will). ElBamino 153 — 3y
0
Hey NGC4637 I haven't been on in a few days but, I just did some testing. It works perfectly fine in a LocalScript. Sorry for the late response. The problem is it's on visible to the local player when I want it to be visible to the server and other players. What can I do to fix this? ElBamino 153 — 3y
Ad

Answer this question