So I’m making a NPC thing where a player hit a NPC with a rocket and the NPC will walk to the player, Here are the scripts(btw I just remove the codes that make the NPC walk to the player to make it shorter)
local script parented to a player tool
local player = game.Players.LocalPlayer
hit.Parent.Hitted:FireServer(game.Workspace:FindFirstChild(player.Name)
script parented to the NPC
local function FindHittedBy(Player)
local target
if Player ~= nil then
print(Player.Parent)
end
return target
end
script.Parent.Hitted.OnServerEvent:Connect(function(Player)
local torso = FindHittedBy(Player)
end)
for the function FindHittedBy, there is a print that print the player character parent and it prints Players which is the service Players but it should be workspace because in the remote event parameter we pass the player character.
I’ve been trying to fix this for a while but I can’t, I tryed to pass the player name as the parameter and make the script find the player character in workspace, there wasn’t any error for that but when I try to refernce the HumanoidRootPart, the HumanoidRootPart is nil(which I’m pretty sure that the object is the player from Players). So I’m just really confuse why the script is looking at the player from Players instead of workspace when I refernce it to the workspace.
What are you trying to do? You’re physically printing the parent of the player, which is game.Players. You’re also defining target but not putting anything, so it is nil… ?
I’m trying to get the player character humanoidrootpart position in the workspace but the humanoidrootpart is nil(The humanoidrootpart does exist in the player character)
Because you put the player argument in the wrong place. The server script receives the request from the client, the parameters are player who fired the event and the arguments. The player who fired the event argument is, of course, a Player object/
In your server script, it should be:
script.Parent.Hitted.OnServerEvent:Connect(function(playerWhoFiredTheEvent, Player)
local torso = FindHittedBy(Player)
end)