Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why Does This First Script Work But The Other Doesn't Work?

First Script:

local Button = script.Parent
 
function onTouch(Brick)
    local Player = Brick.Parent:findFirstChild("Humanoid")
    if (Player ~= nil) then
        local Location = game:GetService('Players'):GetPlayerFromCharacter(Player.Parent)
    if Location:WaitForChild("leaderstats").Gold.Value >= 20 then
for i = 1,1 do
         Location:WaitForChild("leaderstats").Gold.Value  =  Location:WaitForChild("leaderstats").Gold.Value - 20
        script.Parent.Parent.Name = "Yay"
		local Color1 = BrickColor:Random()
		local Color2 = BrickColor:Random()

		script.Parent.Parent.Wall1.BrickColor = Color1
		script.Parent.Parent.Wall2.BrickColor = Color1
		script.Parent.Parent.Wall3.BrickColor = Color1

		script.Parent.Parent.Floor.BrickColor = Color2
		script.Parent.Parent.Head.BrickColor = Color2
		script.Parent.Parent.Roof.BrickColor = Color2
end
        end
    end
end
 
Button.Touched:connect(onTouch)

Second Script :

local Button = script.Parent
 
function onTouch(Brick)
    local Player = Brick.Parent:findFirstChild("Humanoid")
    if (Player ~= nil) then
        local Location = game:GetService('Players'):GetPlayerFromCharacter(Player.Parent)
    if Location:WaitForChild("leaderstats").Gold.Value >= 20 then
for i = 1,1 do
         Location:WaitForChild("leaderstats").Gold.Value  =  Location:WaitForChild("leaderstats").Gold.Value - 20
        script.Parent.Parent.Name = Player .. "'s House"
		local Color1 = BrickColor:Random()
		local Color2 = BrickColor:Random()

		script.Parent.Parent.Wall1.BrickColor = Color1
		script.Parent.Parent.Wall2.BrickColor = Color1
		script.Parent.Parent.Wall3.BrickColor = Color1

		script.Parent.Parent.Floor.BrickColor = Color2
		script.Parent.Parent.Head.BrickColor = Color2
		script.Parent.Parent.Roof.BrickColor = Color2
end
        end
    end
end
 
Button.Touched:connect(onTouch)

1 comment

0

difference is in line ten

1 answer

✓ Accepted answer
 script.Parent.Parent.Name = Player.Name .. "'s House"

if this helped +1, and if it answered check mark :)

This discussion is preserved as it was. New answers, comments, and votes are closed.