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

Why doesn't this change texture?

Asked by 9 years ago

This script is suppose to check the value of something when its changed, and change the texture of a decal depending on the number after the value was changed. If this makes any sense and you can help me, here is the code. Nothing shows up in the output.

-- Made by AwsomeSpongebob
Face = script.Parent.Face.Texture
FaceValue = script.Parent.Value
FaceVal = FaceValue.Value

FaceValue.Changed:connect(function()
    if FaceVal == 0 then
        Face = ("rbxasset://textures/face.png")
    elseif FaceVal == 1 then
        Face = ("http://www.roblox.com/asset/?id=26434948")
    elseif FaceVal == 2 then
        Face = ("http://www.roblox.com/asset/?id=13079565")
    elseif FaceVal == 3 then
        Face = ("http://www.roblox.com/asset/?id=29291814")
    elseif FaceVal == 4 then
        Face = ("http://www.roblox.com/asset/?id=69252500")
    elseif FaceVal == 5 then
        Face = ("http://www.roblox.com/asset/?id=25553966")
    elseif FaceVal == 6 then
        Face = ("http://www.roblox.com/asset/?id=28440649")
    elseif FaceVal == 7 then
        Face = ("http://www.roblox.com/asset/?id=21439548")
    elseif FaceVal == 8 then
        Face = ("http://www.roblox.com/asset/?id=69714134")
    elseif FaceVal == 9 then
        Face = ("http://www.roblox.com/asset/?id=149124698")
    elseif FaceVal == 10 then
        Face = ("http://www.roblox.com/asset/?id=31142001")
    elseif FaceVal == 11 then
        Face = ("http://www.roblox.com/asset/?id=112805849")
    end
end)

1 answer

Log in to vote
1
Answered by 9 years ago

There are three lines, that I can see with your script is that the Values at the top of the script are out of order here is a fixed version of your script:

-- Made by AwsomeSpongebob, and fixed by Darkness246810
Face = script.Parent:WaitForChild('Face') -- Wait for things!
FaceVal = script.Parent:WaitForChild('Value') -- Wait for things!

FaceValue.Changed:connect(function()
    if FaceVal.Value == 0 then -- It is best do it this way!
        Face.Texture = ("rbxasset://textures/face.png") -- Same Here!
    elseif FaceVal.Value == 1 then
        Face.Texture = ("http://www.roblox.com/asset/?id=26434948")
    elseif FaceVal.Value == 2 then
        Face.Texture = ("http://www.roblox.com/asset/?id=13079565")
    elseif FaceVal.Value == 3 then
        Face.Texture = ("http://www.roblox.com/asset/?id=29291814")
    elseif FaceVal.Value == 4 then
        Face.Texture = ("http://www.roblox.com/asset/?id=69252500")
    elseif FaceVal.Value == 5 then
        Face.Texture = ("http://www.roblox.com/asset/?id=25553966")
    elseif FaceVal.Value == 6 then
        Face.Texture = ("http://www.roblox.com/asset/?id=28440649")
    elseif FaceVal.Value == 7 then
        Face.Texture = ("http://www.roblox.com/asset/?id=21439548")
    elseif FaceVal.Value == 8 then
        Face.Texture = ("http://www.roblox.com/asset/?id=69714134")
    elseif FaceVal.Value == 9 then
        Face.Texture = ("http://www.roblox.com/asset/?id=149124698")
    elseif FaceVal.Value == 10 then
        Face.Texture = ("http://www.roblox.com/asset/?id=31142001")
    elseif FaceVal.Value == 11 then
        Face.Texture = ("http://www.roblox.com/asset/?id=112805849")
    end
end)
  • This should work!
0
Thanks!But why use WaitForChild instead of just telling it where it is? AwsomeSpongebob 350 — 9y
0
Like using script.parent.value? AwsomeSpongebob 350 — 9y
0
The value might not have loaded when you try to find it! TheDarkOrganism 173 — 9y
0
Oh ok. Thanks! :D AwsomeSpongebob 350 — 9y
Ad

Answer this question