How to fix this?

  1. What do you want to achieve? Fix my simple script.

  2. What is the issue? My script is not working.

  3. What solutions have you tried so far? I tried to look at DevForum but i din’t found an solution.

My script:

local event = game.ReplicatedStorage:WaitForChild("ToolBackpackEvent")

event.OnServerEvent:Connect(function(player)
	local char = player.Character
	local tool = player.Backpack.Gun
	print("tool parent is " .. tool.Parent)
end)

Its saying that the gun is not a parent of the player’s backpack, why this is happening?

2 Likes

Well, is Gun a child of the backpack?

3 Likes

Yes, i really dont know how to fix this.

1 Like

This seems really weird, can you show the error message, and an image of the backpack and its children in the explorer.

1 Like

Here, i tried this with another tool

It’s not saying gun is not a valid member, it’s saying Killstreak is not a valid member.

1 Like

May I ask, what is the purpose of this function, clearly the tool, which is player.Backpack.Gun has a parent of player.Backpack, so why are you checking this?

try to search the gun with
player.Backpack:WaitForChild("Gun")

Try this?

local event = game.ReplicatedStorage:WaitForChild("ToolBackpackEvent")

event.OnServerEvent:Connect(function(player)
	local char = player.Character
	local tool = player.Backpack:WaitForChild("Gun")
	print("tool parent is " .. tool.Parent)
end)
1 Like

the gun was cloned and placed in the backpack from client-side
or if the tool didnt appear on the toolbar, it was deleted by some script

You can’t get tools from the server that were placed by the client. You need to fire a RemoteEvent to place it in their backpack.

2 Likes

tell that to the original poster, not me

it worked, but it happens every time I put it in my backpack

1 Like

do you have a local script that calls the remote event?

1 Like

Yes,

local player = game.Players.LocalPlayer

local rs = game.ReplicatedStorage
local Event = rs.CharEvent
local backpack = rs.CharBackpack


script.Parent.Changed:Connect(function()
	if script.Parent.Value == 4 then
		Event:FireServer() 
	else
		backpack:FireServer()
		
	end
	
end)

That script isn’t firing the same event that the server script is having problems with. They’re named differently. What LocalScript fires the ToolBackpackEvent RemoteEvent?

1 Like

Can you show the error line and the model where it’s positioned at?