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

Can't get a script to change a decal?

Asked by
corbenv 17
4 years ago
Edited 4 years ago

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?

2 answers

Log in to vote
0
Answered by
OnaKat 444 Moderation Voter
4 years ago
Edited 4 years ago

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 ~=

Conditional Statements

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

0
Thanks! corbenv 17 — 4y
Ad
Log in to vote
0
Answered by
Lualaxy 78
4 years ago

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)

Answer this question