Claim/unclaim script not functioning properly

another day another script gutted for scraps and used for my own needs
im not entirely sure why this script isnt doing the thing i told it to do :3

script.Parent.ClaimPrompt.Triggered:Connect(function(plr)
	if plr.Character:WaitForChild("OwnsHouse").Value == false and script.Parent.Owner.Value == "" then
		script.Parent.Owner.Value = plr.Name
		script.Parent.OwnerName.SurfaceGui.TextLabel.Text = plr.Name.."'s land"
		script.Parent.ClickDetector.MaxActivationDistance = 16
		script.Parent.ClaimPrompt.ActionText = "Unclaim"
		plr.Character:WaitForChild("OwnsHouse").Value = true
	end
end)
script.Parent.ClaimPrompt.Triggered:Connect(function(plr)
	if script.Parent.Owner.Value == plr.Name then
		script.Parent.Owner.Value = ""
		script.Parent.ClickDetector.MaxActivationDistance = 0
		script.Parent.OwnerName.SurfaceGui.TextLabel.Text = "unowned land"
		script.Parent.ClaimPrompt.ActionText = "Claim"
		plr.Character:WaitForChild("OwnsHouse").Value = false
	end
end)
game.Players.PlayerRemoving:Connect(function(plr)
	if script.Parent.Owner.Value == plr.Name then
		script.Parent.Owner.Value = ""
		script.Parent.ClickDetector.MaxActivationDistance = 0
		script.Parent.OwnerName.SurfaceGui.TextLabel.Text = "unowned land"
		script.Parent.ClaimPrompt.ActionText = "Claim"
	end
end)

image


it’s likely something very obvious but i just cant see it LOL

Probably because both functions run after another, so when you set the owner text to “”, the other script thinks that there wasn’t an owner in the first place and sets you back to the owner.

Code:

script.Parent.ClaimPrompt.Triggered:Connect(function(plr)
	if script.Parent.Owner.Value == plr.UserId then
		script.Parent.Owner.Value = ""
		script.Parent.ClickDetector.MaxActivationDistance = 0
		script.Parent.OwnerName.SurfaceGui.TextLabel.Text = "unowned land"
		script.Parent.ClaimPrompt.ActionText = "Claim"
		plr.Character:WaitForChild("OwnsHouse").Value = false
	elseif plr.Character:WaitForChild("OwnsHouse").Value == false and script.Parent.Owner.Value == "" then
		script.Parent.Owner.Value = plr.UserId
		script.Parent.OwnerName.SurfaceGui.TextLabel.Text = plr.Name.."'s land"
		script.Parent.ClickDetector.MaxActivationDistance = 16
		script.Parent.ClaimPrompt.ActionText = "Unclaim"
		plr.Character:WaitForChild("OwnsHouse").Value = true
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	if script.Parent.Owner.Value == plr.UserId then
		script.Parent.Owner.Value = ""
		script.Parent.ClickDetector.MaxActivationDistance = 0
		script.Parent.OwnerName.SurfaceGui.TextLabel.Text = "unowned land"
		script.Parent.ClaimPrompt.ActionText = "Claim"
	end
end)

I would also be logging the owners via UserId, not their name because that can be changed.

1 Like

Yo thanks! Perfect fix!! I hadn’t realized it functioned like that lol

1 Like

For some reason this stopped functioning and I don’t know why, so I’m reopening this subject :frowning:

You’re using the exact same script as earlier and it just stopped working?

Do you use that .Owner value anywhere else?

1 Like

Yes I’m using the exact script you wrote for me, and “Owner” doesn’t seem to exist anywhere else. I’m not quite sure why it simply stopped working.

What doesn’t “work” about it?

1 Like

As in you can’t remove ownership using the unclaim button, just like the original issue. I’m not quite sure why.

Tell me what this prints:

script.Parent.ClaimPrompt.Triggered:Connect(function(plr)
	print(plr.UserId)
	print(script.Parent.Owner.Value)
	if script.Parent.Owner.Value == plr.UserId then
		script.Parent.Owner.Value = ""
		script.Parent.ClickDetector.MaxActivationDistance = 0
		script.Parent.OwnerName.SurfaceGui.TextLabel.Text = "unowned land"
		script.Parent.ClaimPrompt.ActionText = "Claim"
		plr.Character:WaitForChild("OwnsHouse").Value = false
	elseif plr.Character:WaitForChild("OwnsHouse").Value == false and script.Parent.Owner.Value == "" then
		script.Parent.Owner.Value = plr.UserId
		script.Parent.OwnerName.SurfaceGui.TextLabel.Text = plr.Name.."'s land"
		script.Parent.ClickDetector.MaxActivationDistance = 16
		script.Parent.ClaimPrompt.ActionText = "Unclaim"
		plr.Character:WaitForChild("OwnsHouse").Value = true
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	if script.Parent.Owner.Value == plr.UserId then
		script.Parent.Owner.Value = ""
		script.Parent.ClickDetector.MaxActivationDistance = 0
		script.Parent.OwnerName.SurfaceGui.TextLabel.Text = "unowned land"
		script.Parent.ClaimPrompt.ActionText = "Claim"
	end
end)
1 Like

Prints from claiming and trying to unclaim:
image

Do you use OwnsHouse anywhere else?

1 Like

This is the only other script the build uses (just to open and close the door).

local frame = script.Parent
local clickDetector = frame:WaitForChild("ClickDetector")
local opened = frame.Parent:WaitForChild("Opened")

local debounce = true
clickDetector.MouseClick:Connect(function()
	if debounce == true then
		debounce = false
		if opened.Value == true then
			opened.Value = false
			frame.Transparency = 0
			frame.CanCollide = true
		else
			opened.Value = true
			frame.Transparency = 0.5
			frame.CanCollide = false
		end
		wait(0.35)
		debounce = true
	end
end)

The player morph (in ServerScriptService) has the OwnsHouse value, and there are no other mentions of Owner or Ownshouse anywhere else in the game.

The bug could be because when you reset, you don’t set the OwnsHouse value back to true.

Code:

local Players = game:GetService("Players")

local DoorFrame = script.Parent

DoorFrame.ClaimPrompt.Triggered:Connect(function(plr)
	print(plr.UserId)
	print(DoorFrame.Owner.Value)
	if DoorFrame.Owner.Value == plr.UserId then
		DoorFrame.Owner.Value = ""
		DoorFrame.ClickDetector.MaxActivationDistance = 0
		DoorFrame.OwnerName.SurfaceGui.TextLabel.Text = "unowned land"
		DoorFrame.ClaimPrompt.ActionText = "Claim"
		plr:SetAttribute("OwnsHouse", false)
	elseif not plr:GetAttribute("OwnsHouse") and DoorFrame.Owner.Value == "" then
		DoorFrame.Owner.Value = plr.UserId
		DoorFrame.OwnerName.SurfaceGui.TextLabel.Text = plr.Name.."'s land"
		DoorFrame.ClickDetector.MaxActivationDistance = 16
		DoorFrame.ClaimPrompt.ActionText = "Unclaim"
		plr:SetAttribute("OwnsHouse", true)
	end
end)

Players.PlayerRemoving:Connect(function(plr)
	if DoorFrame.Owner.Value == plr.UserId then
		DoorFrame.Owner.Value = ""
		DoorFrame.ClickDetector.MaxActivationDistance = 0
		DoorFrame.OwnerName.SurfaceGui.TextLabel.Text = "unowned land"
		DoorFrame.ClaimPrompt.ActionText = "Claim"
	end
end)
1 Like

Yeah this script didn’t change anything either :smiling_face_with_tear: