Me and a friend are creating a tycoon to learn scripting better, sorry if this is a simple task, we just can’t figure it out! We want the parts coming out of the “dropper” to be red, but the script does not do that. It does everything else like making the position and size, but It just does not turn red for some reason. We have tried using BrickColor and that doesn’t work either.
part = script.Parent.Parent
clickdetector = script.Parent
debounce = false
wait()
clickdetector.MouseClick:Connect(function(plr)
local player = plr
if debounce == false then
debounce = true
local block = Instance.new("Part", workspace.Folder)
block.Color = Color3.fromRGB(255, 0, 0)
block.Position = Vector3.new(-330.586, 502.959, -511.667)
block.Size = Vector3.new(1, 1, 1)
block.Anchored = false
block.Name = "DispensedPart"
wait(0.4)
debounce = false
return player
end
end)
I cant seem to reproduce this behaviour with the code you provided so it must be something else in your game causing this. I also can’t see anything wrong with your code and when I test it the part is red. Are you sure this is the script causing the problem?
While I am here I will suggest a couple changes you could make to your script that are better practices:
Before defining any variables you should put local before it. I can’t remember the technical details behind doing this but generally it is better.
When using Instance.new() you shouldn’t use the parent argument because doing this increases the amount of internal calls. Instead you should change all the necessary properties then parent the object as the last thing. You may want to read this thread for more information: PSA: Don't use Instance.new() with parent argument. Here is a code sample as well:
local Part = Instance.new("Part")
Part.Color = Color3.fromRGB(255, 0, 0)
Part.Size = Vector3.new(1, 1, 1)
Part.Parent = workspace -- Parents the part
You should remove the wait() at the beginning of your code because it is unnecessary. You should avoid using wait where you can because some developers have experienced incorrect or longer wait times when using wait().