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

Why Does My Buy A House Script Not Work?

Asked by
jacobwow 140
10 years ago

When I click the head, it does nothing. I have my click detector in the Head and everything seems to be fine. No error messages but nothing happens. Here is the script:

local Button = script.Parent

function onClick()
    local Player = Brick.Parent:findFirstChild("Humanoid")
    if (Player ~= nil) then
        local Location = game:GetService('Players'):GetPlayerFromCharacter(Player.Parent)
        local Button = Location.leaderstats.Gold
        if Location.leaderstats.Gold.Value > 19 then
        Location.leaderstats.Gold.Value = Location.leaderstats.Gold.Value - 20
        script.Parent.Parent.Name = Player .. "'s House"
        end
    end
end

Target.ClickDetector.MouseClick:connect(onClick)

1 answer

Log in to vote
2
Answered by
HexC3D 830 Moderation Voter
10 years ago
local Button = script.Parent

function onClick()
    local Player = Brick.Parent:findFirstChild("Humanoid") -- what is "Brick"!! Define it.
    if (Player ~= nil) then
        local Location = game:GetService('Players'):GetPlayerFromCharacter(Player.Parent)
    if Location:WaitForChild("leaderstats").Gold.Value >= 19 then
for i = 1,1 do
         Location:WaitForChild("leaderstats").Gold.Value  =  Location:WaitForChild("leaderstats").Gold.Value - 20
        script.Parent.Parent.Name = Player .. "'s House"
end
        end
    end
end

Button.ClickDetector.MouseClick:connect(onClick) -- What was target, Define it!!

I changed a couple things to work out, you also used the same variable "Button" twice also.

Also if you can figure out brick and define it, then your problem is solved. also Target.

If this helped +1 and if I answered your question check mark :)

0
You have a flaw on line 7. It's `>=` not `=>` Shawnyg 4330 — 10y
0
q.q HexC3D 830 — 10y
0
Thanks, Typos. HexC3D 830 — 10y
Ad

Answer this question