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:
local isOn = true function on() script.Parent.Parent.screen.ison.Texture = rbxassetid://1400090149 isOn = true end function off() Parent.screen.ison.Texture = rbxassetid://2675785344 isOn = false end function onclicked() if isOn = true then off() else on() end end 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 :
local isOn = true function on() script.Parent.Parent.screen.ison.Texture = "rbxassetid://1400090149" isOn = true end function off() Parent.screen.ison.Texture = "rbxassetid://2675785344" isOn = false end function onclicked() if isOn == true then off() else on() end end 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:
rbxassetid://2675785344
But it should look like this:
"rbxassetid://2675785344"
So your script only needs a few "
local isOn = true function on() script.Parent.Parent.screen.ison.Texture = "rbxassetid://1400090149" isOn = true end function off() Parent.screen.ison.Texture = "rbxassetid://2675785344" isOn = false end function onclicked() if isOn = true then off() else on() end end script.Parent.ClickDetector.MouseClick:Connect(onclicked)