Works great in studio play mode but not in a proper game server.

basically its supposed to find the key from lighting then change the value and give it to the player.

When tested it copies then deletes itself after a few seconds after not fully loading (no decal etc).

function onTouched(hit)
	if hit.Parent == nil then return end
	if (hit.Parent:findFirstChild("Humanoid") == nil) then return end
	local human = hit.Parent:findFirstChild("Humanoid") 
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if (game.Workspace:findFirstChild(human.Parent.Name.."House") ~= nil) then Message(player, "You already own a house.") return end
	if (human ~= nil) and debounce == false then
		debounce = true
		local stats = player:findFirstChild("leaderstats")
		if stats ~= nil then 
			local cash = stats:findFirstChild("Money")
			if cash.Value > (upgradecost-1) then 
				cash.Value = cash.Value - upgradecost 
				local housemarker= Instance.new("StringValue")
				housemarker.Parent = game.Workspace
				housemarker.Name = human.Parent.Name.."House"
				housemarker.Value = script.Parent.Parent.Parent.Name
				Message(player, "You now own this house.")
				--script.Parent.Parent.Parent.Vacant.Name = player.Name.."'s House"
				local stuff = script.Parent.Parent:GetChildren()
				for x = 1, #stuff do
					if stuff[x].ClassName == "Model" then
						stuff[x].Name = player.Name.."'s House"
					elseif stuff[x].ClassName == "Part" then
						stuff[x].Transparency = 1
						stuff[x].CanCollide = false
						if stuff[x].Name == "Sign" then 
							stuff[x].Decal.Transparency = 1
						end
					end
				end
				script.Disabled = true
				housemodel.MainHouse.Owner.Value = player.Name
				if player.Backpack:findFirstChild("Key") == nil and player.Character:findFirstChild("Key") == nil then
					local keycopy = game.Lighting.Key:clone()
					keycopy.Value.Value = player.Name
					keycopy.Parent = player.Character
				end
			else
				local message = Instance.new("Message")
				message.Text = "You don't have enough money."
				message.Parent = player
				wait(3)
				message:remove()	
			end
			wait(3)
			debounce = false
		end
	end
end

script.Parent.Touched:connect(onTouched)

1 comment

0

Does anyone know how to fix this?