My script not working

Hello,

I have a problem .My script doesn’t work for some reasons. No error were found and I also tried to debug but I can’t see the problems any help is appreciated :slight_smile:

here is my script;

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:FindFirstChild("Humanoid")

for i , v in pairs(script.Parent:GetChildren())do
	if v:IsA("ImageButton") then
		
		v.Activated:Connect(function()
			print("bruh")
			
			if v.CanDes.Value == false then
				v.CanDes.Value = true
				v.BackgroundColor3 = Color3.fromRGB(75,75,75)
				
				local item = game.ReplicatedStorage:FindFirstChild(v.Name)
				
				if item and item.Parent ~= player.Backpack or item.Parent ~= char then
					
					local clone = item:Clone()
					clone.Parent = player.Backpack
					
					hum:EquipTool(clone)
				end
			end
		end)
	end
end
v.Activated:Connect(function()

Are you trying to make it to where if you click the button it does all of the below or something?

yes.only when it clicked (((()))

If you want it to function via clicking the button, replace

v.Activated:Connect(function()

with

v.MouseButton1Down:Connect(function()

This way, when you click the button the code below will actually run and work.

same thing happend. no error or printing

local item = game.ReplicatedStorage:FindFirstChild(v.Name)

I noticed this, what are you trying to get from ReplicatedStorage? The button or the item?

its an item ((((()))) asfgfaeg

It’s a local script. The tool won’t appear because it’s client sided. You need to give the tool via the server.

Use remote functions to achieve this.

Is it okay if I use remote event instead??

Sorry yes. Remote event will also work.

Let me know if that works. If not I’ll look again.

welp still not working…the output only printing at thi line only

for i , v in pairs(script.Parent:GetChildren())do
     print("hi")

this is the changes:

game.ReplicatedStorage.EquipTool.OnServerEvent:Connect(function(player , item)
	
	local tol = game.ReplicatedStorage:FindFirstChild(item)
	local char = player.Character or player.CharacterAdded:Wait()
	
	if tol and tol:	IsA("Tool") then
		if tol.Parent ~= char or tol.Parent ~= player.Backpack then
			
			local clone = tol:Clone()
			tol.Parent = player.Backpack
			
			print(tol.Name)
		end
	end
end)

To verify, you are sending the tool instance or tool name?

tool name (((((())))) oihgoujbgdaiopnhbt

local char = player.Character

Try just that remove the part after or.
Cause it could be waiting for the character to join again causing it to stop.

nope … nothing happen …is it bug??

Hmmm. I’m on my phone atm. So bare with me.

So. I can’t see very much on my phone. If there’s no answer by tomorrow I’ll retype the code for you on my pc.

1 Like

ok then… thanks very much for replying