So i've been trying to get this script to change the decal on a T.V. I made's screen from black to a different decal. on the screen I've already got a decal, which is the black screen. On the power button I've got a click detector linked to a function in my script. My problem is that it wont work.
Here is the code:
01 | local isOn = true |
02 |
03 | function on() |
04 | script.Parent.Parent.screen.ison.Texture = rbxassetid:// 1400090149 |
05 | isOn = true |
06 | end |
07 |
08 | function off() |
09 | Parent.screen.ison.Texture = rbxassetid:// 2675785344 |
10 | isOn = false |
11 | end |
12 |
13 | function onclicked() |
14 | if isOn = true then off() else on() end |
15 | end |
16 |
17 | script.Parent.ClickDetector.MouseClick:Connect(onclicked) |
Here is a pic of my studio if it helps: https://ibb.co/PYW3NbG
It might not show it here, but in my original, it displays a red line under the first dash in rbxassetid://1400090149. Why is this happening and how do I fix it?
1
rbxassetid://1400090149
Put it as string.
"rbxassetid://1400090149"
Do this with others too
2
If then
equal ==
more than >
more/equal >=
less than <
less/equal <=
not equal ~=
Script :
01 | local isOn = true |
02 |
03 | function on() |
04 | script.Parent.Parent.screen.ison.Texture = "rbxassetid://1400090149" |
05 | isOn = true |
06 | end |
07 |
08 | function off() |
09 | Parent.screen.ison.Texture = "rbxassetid://2675785344" |
10 | isOn = false |
11 | end |
12 |
13 | function onclicked() |
14 | if isOn = = true then off() else on() end |
15 | end |
16 |
17 | script.Parent.ClickDetector.MouseClick:Connect(onclicked) |
You can see error in output. Open it in view in Roblox Studio
The reason why it doesn't change is because you didn't put the whole rbxassetid in a string. Yours looks like this:
1 | rbxassetid:// 2675785344 |
But it should look like this:
So your script only needs a few "
01 | local isOn = true |
02 |
03 | function on() |
04 | script.Parent.Parent.screen.ison.Texture = "rbxassetid://1400090149" |
05 | isOn = true |
06 | end |
07 |
08 | function off() |
09 | Parent.screen.ison.Texture = "rbxassetid://2675785344" |
10 | isOn = false |
11 | end |
12 |
13 | function onclicked() |
14 | if isOn = true then off() else on() end |
15 | end |
16 |
17 | script.Parent.ClickDetector.MouseClick:Connect(onclicked) |