Script not working idk why. pls help

hello so i got this script

local player = script.Parent.Parent.Parent.Parent.Parent
local findTool = player:WaitForChild("BackPack"):FindFirstChild("AK-101")
script.Parent.MouseButton1Click:Connect(function(click)
	if player.leaderstats.Cash.Value >= 100 then
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 100
		game.ReplicatedStorage.Tools["AK-101"]:Clone().Parent = player:WaitForChild("Backpack")
	elseif findTool then
	end
	end)

and it’s suppost to copy a tool into my backpack but if i already own it then it shouldn’t do that. but even when i don’t have it, it still doesn’t copy it into my backpack, why?

2 Likes

Is this a local script? If so you should do player = game.Players.LocalPlayer
Also, it’s finding in by the tool after it gives it since you’re doing wait for child. You should do find first child. — misread the findfirstchild

1 Like

Well uhh its a serverscript since i dont know how to use remote events.

1 Like

Oh, you should be using local script and a remote event. The click isn’t working since it’s a server script. All you have to do is fire the server with the data and find the data using a server script. The documentation makes remote events easy to understand!

But the problem is that i just don’t understand remote events.

And it’s like almsot night for me so i gotta be quick with stuff.

They’re pretty easy. It’s just sending data and waiting for the data. In a local script just RemoteEvent:FireServer(-data-) then on server script
You just do RemoteEvent:OnServerEvent:Connect(function(plr,-data-) end)

— documentation: RemoteEvent | Documentación del Centro de creación de Roblox

To be honest im just tired of trying to fix that thing, i guess my game will just suck. if u wanna play it here’s the link. a game in which you shoot zombies [UPDATE] - Roblox

I can send you code or a model thing when I get on computer

That would be great! Thank you.

1 Like

Okay so uhhhhhh it works, but idk how to make it stop giving the player a tool. It prints “player has tool” but i still get the tool.

example

local playerowned = player["StarterPack"]

if playerowned:FindFirstChild["Your Tool Name"] then
 print("Player Does have tools")
else
 print("Player Doesnt have tools")
end


if its doesnt work its prob script error

edit : try this

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Tools = ReplicatedStorage["Tools"]["AK-101"]
local Price = 100

script.Parent.MouseButton1Click:Connect(function(player)
	local findTool = player:WaitForChild("BackPack"):FindFirstChild("AK-101")
	
	if player.leaderstats.Cash.Value >= Price and not findTool then
		
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - Price
		Tools:Clone()
		Tools.Parent = player:WaitForChild("BackPack")
		
	else
		print("something went wrong")
	end
end)

It shouldn’t be giving the tool. I don’t see anything that could cause that.