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

Why Does My Buy A House Script Not Work?

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

✓ Accepted answer
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 :)

3 comments

0

You have a flaw on line 7. It's >= not =>

0

q.q

0

Thanks, Typos.

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