My script is not working as intended

I’m trying to make it so if a player uses the proximity prompt it will check if it has 5 or more coins and then if the player does then it will give the item to the player.

local Players = game:GetService("Players").localplayer
local player = Players.LocalPlayer
local bloxxycola = game.Lighting.BloxyCola:Clone()

if script.Parent.Triggered then
	if player:WaitForChild("leaderstats").Coins == 5 then
		bloxxycola.Parent = game.StarterPack
	end
end

You can’t use game.Players.LocalPlayer in a server script. Also you shouldn’t be using an if statement but rather an event.

script.Parent.Triggered:Connect(function(player)
    — Code
end)
if player:WaitForChild("leaderstats").Coins.Value >= 5 then

if player:WaitForChild("leaderstats").Coins == 5 then
Here,you’re comparing an instance with a number, which is causing an error.
Thus- add .Value after the Coins.

bloxxycola.Parent = game.StarterPack

If you want to clone the bloxycola to the player -
You can either access to the player’s Backpack or StarterGear
[If you want to detect if a player is equipping a tool, you’ll check it on their character].

Or the character to see if they have it equipped

You can’t compare an instance to a number. Add a .Value at the end of Coins.

changed
(char limit ) (char limit ) (char limit )

It says in the output localplayer is not a valid member of Players “Players”

If that’s a server script, then you can’t do that.

You could get the local player in a different way when using normal scripts.

Do i have to put the script in serverscriptservice? Because it’s a normal script in the proximity prompt

Do you mind sending a screenshot of the relevant stuff?

1 Like

Check the post that I said earlier, this will explain your error and fix it