Proximity Prompt shop will not work

I want to make a Proximity Prompt shop, but will not work.

Issue is the following:
image (Script)
image (Local Script)

I tried to change the script from local script to script and vise versa and changed the names

script.Parent.Triggered:Connect(function()
	local ReplicatedStorage = game:GetService("ReplicatedStorage")
	local Item = ReplicatedStorage.ShopItems.BloxyCola
	local Price = 200
	local player = game.Players.LocalPlayer
	local leaderstats = player:WaitForChild("leaderstats")
	
	if leaderstats >= Price then
		leaderstats.Playtime.Value = leaderstats.Playtime.Value - Price
		local cloned = Item:Clone()
		cloned.Parent = player.Backpack
		cloned.Parent = player.StarterGear
	end
end)

I also have the leaderstats script but it has datastore keys in it so not showing (idk what u can do with them but i think ur not supposted to share them)

1 Like

If you don’t know, you cannot access the LocalPlayer inside a Server Script, however I believe you can get the player with the first parameter that the Triggered event gives you

script.Parent.Triggered:Connect(function(player)
	local ReplicatedStorage = game:GetService("ReplicatedStorage")
	local Item = ReplicatedStorage.ShopItems.BloxyCola
	local Price = 200
	local leaderstats = player:WaitForChild("leaderstats")
	
	if leaderstats >= Price then
		leaderstats.Playtime.Value = leaderstats.Playtime.Value - Price
		local cloned = Item:Clone()
		cloned.Parent = player.Backpack
		cloned.Parent = player.StarterGear
	end
end)

If that doesn’t work, could you try adding some print statements to it?

1 Like

I will try putting print statements but I know the line that is causing the issue, and forgot putting print statements

image
This is what I got after putting it in, Server Script btw.

You’re trying to compare the leaderstats Instance (Assuming a folder) with a NumberValue (Or the Price variable, change that to:

if leaderstats.Playtime.Value >= Price then
2 Likes

Let me test that, I usually not notice these small bugs because I always rely on the console to give me all the debug info, most of the time it wont really give me much info because I am not a good script and a debugger.

Oof, imagine this then:

if leaderstats >= Price then

Is basically:

if Instance >= Number then

Resulting an in error, as you can’t compare an Instance with a Number value

1 Like

It worked, but wont give me the item, I feel like this I can fix with a few changes but maybe I might have to rely on the devforum for this entire script sadly.

I fixed it finally, I just removed starter gear as the parent. Thanks

1 Like

I was literally gonna say that :sweat_smile: Glad you got it fixed, also I’d recommend changing this:

local cloned = Item:Clone()
cloned.Parent = player.Backpack
cloned.Parent = player.StarterGear

To this:

local cloned = Item:Clone()
local cloned2 = Item:Clone()
cloned.Parent = player.Backpack
cloned2.Parent = player.StarterGear

So that way the Player can keep the item even if they die

1 Like

All right forgot about that :+1: