Problem with claiming system - no errors?

I’m still quite new with scripting so please excuse me if this is a really stupid mistake :sob:

But basically my claiming system that should save to the game won’t work at all (like nothing about it works), but no errors are showing up.

local MarketplaceService = game:GetService("MarketplaceService")
local ClickDetector = script.Parent.Parent.ClickDetector
local DataStoreService = game:GetService("DataStoreService")
local OwnerData = DataStoreService:GetDataStore(script.Parent.Parent.Name)
local clone = game.ServerStorage.SignText:Clone()
local debouce = false
clone.Parent = game.StarterGui
clone.Adornee = script.Parent
clone.Name = script.Parent.Name


local data = Instance.new("Folder")
data.Name = "data"
data.Parent = workspace
local Owner = Instance.new("IntValue")
Owner.Name = script.Parent.Parent.Name
Owner.Value = 0
Owner.Parent = data

if OwnerData:GetAsync("StatueOwners") == 0 then
	print(script.Parent.Parent.Name.." is unclaimed!")
else
	wait()
	local text = game.StarterGui:FindFirstChild(script.Parent.Name)
	local id = game:WaitForChild("data"):WaitForChild(script.Parent.Parent.Name).Value
	local username = game:GetService("Players"):GetNameFromUserIdAsync(tonumber(id))
	text.Text = username
end


ClickDetector.MouseClick:Connect(function(Player)
	local ownerdata = game.Workspace:FindFirstChild("data"):FindFirstChild(script.Parent.Parent.Name)
	local text = game.StarterGui:FindFirstChild(script.Parent.Name)
	if OwnerData:GetAsync("StatueOwners") == 0 then
		text.Text = Player
		script.Parent.Name = Player
		ownerdata.Value = Player.UserId
		wait(1)
		OwnerData:SetAsync("StatueOwners", ownerdata.Value)
	end
end)

*^ I haven’t been able to test the loading data part of it yet if a user id is set as the value, because it won’t let me claim it

Where does it break? Add prints pretty much everywhere and look for when a print is not printed. If everything prints, change what they print. Make them print whatever information is relevant.

This will help you find the source of the issue. Let me know once you know where the issue begins!

Okay so I added prints after every line and it didn’t get past this line:

local id = game:WaitForChild("data"):WaitForChild(script.Parent.Parent.Name).Value

I’m a bit confused though because the value is set to 0, so it shouldn’t be trying to load any data into the game

So it doesn’t obtain the value 0? If it gets 0, then it will try to load a name from the userid 0.

did it print this line? print(script.Parent.Parent.Name…" is unclaimed!") and i need more letters so i am typing this.

It’s supposed to have a value of 0 until first clicked, in which it should change the value to the userid of the person that clicked it — so if it’s never been clicked, it shouldn’t be trying to load anything because of the if OwnerData:GetAsync("StatueOwners") == 0 then right?

No that never printed, I added print lines after every line in the “else” section and those printed, but I’m not sure why it went to else

because it is not getting a value of zero. also can you inform me what “StatueOwners” is?

It went to else because the current owner isn’t 0, try printing what it is. I would guess it currently is nil. Are you certain that the children exist?

I thought that’s where you made a key? I was trying to look around last night about saving data to the game rather than to a user and all I could really find was not using their userid as the key and using something like that, but I’m not good at all with this sort of stuff so I probably didn’t understand it right :sob:

OKAY so I just noticed that it’s game: and not game.Workspace: — I fixed that but it’s still going to else. I also printed the value and it’s printing as 0. But now it’s at least giving some error for it

This is because the value is 0, the values you have been comparing have been different as well.

The 0 you are catching is the datastore, while the 0 you are getting is from the game.

1 Like

did you set “GetNameFromUserIdAsync” to anything?

if not, that’s your error, it is trying to tell what GetNameFromUserIdAsync is but it cannot find it.

Ohh okay I changed all the others to check the value in the game and changed the if OwnerData:GetAsync("StatueOwners") == 0 then to if OwnerData:GetAsync("StatueOwners") > 0 then and it seems to be working now! Thank you so much :smile:

happy to help, i’m glad it worked

1 Like