So, I'm writing a script that when a player talks to a NPC it gives the player a custom item, and the talking script happens in a local script so i'm using a remote event to transfer it into a Server side script because the knife wont show up if given by Local Script, but When a player talks to the NPC they just receive a number of knives equal to the amount of players in a server, if that makes sense. I just want the player who talked to the NPC to receive one knife, here's my code.
local RM = game.ReplicatedStorage:WaitForChild("GiveKnife")
local function GiveKnife(player)
print(player)
local knife = game.ReplicatedStorage.Knife:Clone()
knife.Parent = player.Backpack
wait(1)
end
RM.OnServerEvent:Connect(GiveKnife)
if you need clarification lmk and ill edit the post and respond to you
Edit: The player IS receiving the knives just fine, but they receive knives relevant to how many players there are in the server, for example if there is one player they receive one knife, if there are 10 they will receive 10 knives. I want to prevent this from happening.
This is the full local script, the RE fires from the bottom of it
local HumanoidRootPart = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local UIS = game:GetService("UserInputService")
local Npc = game.Workspace.HelperMan.Head
local Npc2 = game.Workspace.ShadySeller.Head
local RM = game.ReplicatedStorage:WaitForChild("GiveKnife")
UIS.InputBegan:connect(function(keyCode)
if keyCode.keyCode == Enum.KeyCode.E then
if (Npc.Position - HumanoidRootPart.Position).magnitude < 25 then
print("Key E was pressed")
game.Players.LocalPlayer.PlayerGui.SpokenToHelper.Enabled = true
wait(8)
game.Players.LocalPlayer.PlayerGui.SpokenToHelper.Enabled = false
end
end
end)
local HumanoidRootPart = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local UIS = game:GetService("UserInputService")
local Npc = game.Workspace.HelperMan.Head
UIS.InputBegan:connect(function(keyCode)
if keyCode.keyCode == Enum.KeyCode.E then
if (Npc2.Position - HumanoidRootPart.Position).magnitude < 25 then
print("Key E was pressed")
game.Players.LocalPlayer.PlayerGui.SpokenToShady.Enabled = true
wait(6)
game.Players.LocalPlayer.PlayerGui.SpokenToShady.Enabled = false
RM:FireServer()
end
end
end)

3 comments
The first value returned in a RemoteEvent is the client who called it.
The first parameter within an event is always the player
Well, it looks like there's something wrong with the LocalScript which is firing, it will be more helpful if you add the part of the LocalScript which is firing. The script you mentioned above have no errors.