Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Problem with BrickColor on touch?

This script is placed inside a brick, and players are assigned a colour which is in a folder I called Settings, which is placed in the Player, and there's a Brickcolor Value and when this brick is touched, I want the Brick's colour to be the BrickColor Value that the player was assigned, but for some reason this is not working, yet no output.

function onTouched(hit) 
	local check = hit.Parent:FindFirstChild("Humanoid") 
	if check ~= nil then
	local name = hit.Parent.Name
		local user = game.Players:GetPlayerFromCharacter(hit.Parent) 
		local stats = user:FindFirstChild("Settings").Colour

		if stats ~= nil then 
		script.Parent.BrickColor = BrickColor.new(stats.Value)
		end
	end
end
script.Parent.Touched:connect(onTouched) 

2 answers

✓ Accepted answer

Assuming stats is a BrickColorValue and not a string value, you can't make a brickcolor out of a brick color? What you're doing is:

BrickColor.new(BrickColor.Green()) --trying to create brickcolor with another brickcolor

You can't do that so just use stats.Value as the brickcolor

function onTouched(hit) 
    local check = hit.Parent:FindFirstChild("Humanoid") 
    if check then --     ~= nil isn't needed
        local name = hit.Parent.Name
        local user = game.Players:GetPlayerFromCharacter(hit.Parent) 
        local stats = user:FindFirstChild("Settings").Colour

        if stats ~= nil then 
        script.Parent.BrickColor = stats.Value
        end
    end
end
script.Parent.Touched:connect(onTouched) 
script.Parent.Touched:connect(function(Touched)
	if Touched.Parent ~= nil and Touched.Parent:FindFirstChild("Humanoid") ~= nil then
		local User 		=	game.Players:FindFirstChild(Touched.Parent.Name);
		
		local Stats		=	User:WaitForChild("Settings"):FindFirstChild("Colour");

		if Stats ~= nil then
			script.Parent.BrickColor		=	BrickColor.new(Stats.Value);
		end
	end
end)

This is assuming that you're using a StringValue. I know that Yellow just answered it using a BrickColorValue but this will be relevant to anyone who is using a StringValue with the same problem.

1 comment

0

Thanks also for this

This discussion is preserved as it was. New answers, comments, and votes are closed.