Inventory system bug

So It’s a inventory gui, If a player pick the item up the script detects it( The script is in the item)
and the whole server sees the item in their gui but I only want the player that picks it up has it in their gui
script in the item =

local proximityPrompt = script.Parent

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = ReplicatedStorage:WaitForChild("Item")

proximityPrompt.Triggered:Connect(function(player)
    remoteEvent:FireAllClients("NightV")
    print("1")
    script.Parent.Parent:Destroy()
    script.Parent:Destroy()
    script:Destroy()
end)

Local script in Starter Gui.:

local function ItemGet(armor)
    print("2")
    if armor == "Raptor1" then
        --scriptssss
        end
    elseif armor == "Raptor2" then
        ---scriptts
             end
end
Item.OnClientEvent:Connect(ItemGet)

I got a video of what it does.

Not quite sure what the problem is here. Each instance of a local script is running on a per client basis so there’s really no need for the sort of check you’re doing. Are you using FireAllClients() only? If so you can use FireClient(Player) to activate it for only the one player.

1 Like

Read @TimesIllusion’s answer, about using FireClient. But if for some reason you are intending to use your current system, assuming “player” is a player object, you should correct your code to the following:

if player == game.Players.LocalPlayer then
-- The script is here.
end

Also upper case Game has been deprecated, use game.

How could I send data with it, this doesn’t seem to work.

local proximityPrompt = script.Parent

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = ReplicatedStorage:WaitForChild("Item")

proximityPrompt.Triggered:Connect(function(player)
	remoteEvent:FireClient(player, "NightV")
	print("1")
	script.Parent.Parent:Destroy()
	script.Parent:Destroy()
	script:Destroy()
end)

I tried that but it still doesn’t work.

Since the server goes straight to the right client, there’s no need to specify any second argument.

Server Script:

local proximityPrompt = script.Parent

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = ReplicatedStorage:WaitForChild("Item")

proximityPrompt.Triggered:Connect(function(player)
	remoteEvent:FireClient(player)
	print("1")
	script.Parent.Parent:Destroy()
end)

Local Script.

local remoteEvent = ReplicatedStorage:WaitForChild("Item")
remoteEvent.OnClientEvent:Connect(function()
print("Reached the right client!")
end)

Also, when you delete an instance you delete it’s children.

Should I use a different event for every item, becuse In the Local script I do like:

local function ItemGet(player, armor)
	print("2")
 if armor == "Raptor1" then
		---Script
		
 elseif armor == "Raptor2" then
  ---script
  end
end

I’m not really clear on what your trying to do, but yeah you can pass arguments through events, so from the server you could pass the armor name and then on the local script you could check which amour it is and do whatever you have to do.

To send arguments do this:

-- Server
Event:FireServer(Player, ArgumentOne, ArgumentTwo, ArgumentThree)

You can send as many arguments as you like.
And to recieve on the local script do this:

-- Server
Event.OnClientEvent:Connect(function(ArgumentOne, ArgumentTwo, ArgumentThree)
print("Got arguments.")
end)

You only need to pass the player to FireServer, if your using FireAllClients then obviously you don’t need to pass any player object.

2 Likes

Here is a video that explains what it does, so when I pick it up the whole server gets it, it shows all the scripts.
I hope this makes it clear, sorry for taking so long.

Alright, and does everything work the way you want it to now?

No, those are my old scripts that gives everyone the items not the player who picks it up.

I’m not sure what you’re trying to do but it’s possibly because you’re using :FireAllClient() instead of :FireClient()

I tried it but, that doesn’t work, I edited the post to be clearer, so once I pick the item up everyone in the server get’s it in their inventory