PlayerRemoving script error

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    I made a script that can remove the name of a player’s house like what he owns the house when he leaves the game but the script I made does not work

  2. What is the issue? this part of script does not working : local part = script.Parent

part.Touched:Connect(function(hit)
local h = hit.Parent:FindFirstChild(“Humanoid”)
if h then
game.Players.PlayerRemoving:Connect(function(player)
if player.Name == hit.Parent.Name then
script.Parent.Parent.Owner.Part.Bill.Lab.Text = “Nobody’s House”
local Mod = game.ServerStorage.PriceB1
local clone = Mod:clone()
clone.Parent = workspace
clone:MakeJoints()
end
end)

  1. What solutions have you tried so far? i try to change some settings but its still not working

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local part = script.Parent

part.Touched:Connect(function(hit)
	local h = hit.Parent:FindFirstChild("Humanoid")
	if h then
		local plr = hit.Parent.Name
		local plr = hit.Parent.Name
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			local lead = player:FindFirstChild("leaderstats")
			local door = script.Parent
		    local plr = hit.Parent.Name
		    local cash = lead.Bucks
		
	 if game.Players[plr].H.Value == false and game.Players[plr].leaderstats.Bucks.Value >= 200 then
		    game.Players[plr].H.Value = true
			script.Parent.Parent.Owner.Part.Bill.Lab.Text = hit.Parent.Name.."'s House"
			script.Parent.Parent.Price:Destroy()
			cash.Value = cash.Value - 200
			door.CanCollide = false
			door.Transparency = 0.7
            game.Players[plr].PlayerGui.HouseGUI.Frame.ImageLabel["1Blue"].Visible = true
            wait(0.2)
			script:Destroy()	
		else
				end
      if game.Players[plr].H.Value == true then
			end
			game.Players.PlayerRemoving:Connect(function(player)
				if player.Name == hit.Parent.Name then
					script.Parent.Parent.Owner.Part.Bill.Lab.Text = "Nobody's House"
							local Mod = game.ServerStorage.PriceB1 
		                    local clone = Mod:clone()
		                    clone.Parent = workspace
		                    clone:MakeJoints()
		end
				end)
	     end
 end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

You should probably divorce the PlayerRemoving connection from the Touched one first of all. These should be independent systems: buying the house and regenerating one when a player leaves. These systems can be joined by an indicator of some kind that the player owns a house (set by the Touched script) and when the player leaves, the house referenced by that indicator should be regenerated.

1 Like