I have a buy a house with gold script. If you own the house and walk in it heals you, but if you are not the owner you die. However I have a problem, when the buyer dies and walks into his home, it kills him. How can I fix this? The Script:
local Button = script.Parent
local debounce = true
local HasAccess = nil
function onTouch(Brick)
if debounce == true then
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.Parent.Name .. "'s House"
HasAccess = Player
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
script.Parent.CanCollide = false
script.Parent.Transparency = .62
debounce = false
end
end
end
end
end
Button.Touched:connect(onTouch)
function Vip(Brick)
if script.Parent.Parent.Name ~= "House For Sale - 20 Gold" then
local Toucher = Brick.Parent:findFirstChild("Humanoid")
if Toucher ~= nil then
if Toucher == HasAccess then
HasAccess.Health = HasAccess.MaxHealth
else Toucher.Health = 0
end
end
end
end
Button.Touched:connect(Vip)
