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

part colour not changing? --Literally no idea why this isn't working

Asked by 6 years ago

Hi guys I'm trying to change the colour of a block by selecting creating a colour on a Gui, I have a script parented to the part I'm wanting to effect:

local players = game:GetService("Players")
players.PlayerAdded:connect(function (player) 
    wait(1) --this is just to let the player load, it'll be cleaner when im done haha
    local p_colour = require(player.PlayerGui.Gui.TextButton.ModuleScript).colour()
    print(p_colour)
    script.Parent.Color = Color3.new(p_colour)  
end)

And the module script it is referring to is:

local _M = {}

function _M.colour(p_colour)
    p_colour = script.Parent.BackgroundColor3
    print(p_colour)
    return(p_colour)
end

return _M

both of the print value out put the correct Color3 value (255,51,93) but the effected part always changed to black (0,0,0).

I've been trying to fix this for ages and it's probably something stupid that i'm missing...

Thanks for your time!

0
Is the first script a local script? And explain, in detail, what you're trying to do. BTW, ModuleScripts can only be called once in one script. Rare_tendo 3000 — 6y
0
I'm trying to make it so that the player can cutomise the colours of certain furniture parts by selecting a colour on a Gui, at the moment I'm simply using the backgound of a Gui button as the colour to try and make it work. I have the 1st script inside the part which should have it's colour changed and the module script inside the gui button (with the background colour that i'm trying to copy) AlexTheCreator 461 — 6y
0
If the `.color()` returns a color3, you can remove the Color3.new() on line 6 theCJarmy7 1293 — 6y
0
Perfect, that fixed the problem, thakn you very much for the help! AlexTheCreator 461 — 6y
0
You don't require the `Color3.new`. :) TheeDeathCaster 2368 — 6y

2 answers

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

The ModuleScript uses script.Parent... I'm not sure if you should be using that - I doubt script.Parent will swap over to the parent of the script calling it.

Also... ModuleScript) the parenthese.

Also an improvement to your script:

Replace wait(1) with player.CharacterAdded:Wait(); it'll start up the stuff the instant the character is added.

Although about the thing with it turning black... I don't know... unless it might have to do with the ModuleScript's parent.

0
im not trying to swap the script.parent of the script calling the module, im getting the parent of the module script itself :) the closed brackets after modulescript is to close the require argument, it's then followed by the function im trying to call from the module script, is this wrong? dw I know about the character added bit just trying to get the actual thing to work haha, ty though AlexTheCreator 461 — 6y
0
I was trying a different method earlier actually and just sent the script.parent of the script as an argument in the function part of the require line :) :P AlexTheCreator 461 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

"If the .color() returns a color3, you can remove the Color3.new() on line 6" -theCJarmy7

[CLOSED]

Answer this question