Before you say that its stupid, I couldn’t figure out how to see if a target.hit was a player. And I asked for help and then this dude got really mad at me. He couldn’t explain why it worked and what I can do with it so I can understand it better.
So I decided to make another post here. How do I get the character from a Target.Hit?
Heres my serverscript in case you need it:
local Players = game:GetService("Players")
local Tool = script.Parent
local ServerEvent = Tool:WaitForChild("OnFired")
ServerEvent.OnServerEvent:Connect(function(Player, MousePosition, Target)
print(Target)
if typeof(Target) == "Instance" and Players:GetPlayerFromCharacter(Target.Parent) then
print(Target.Parent.Name)
end
end)
local Players = game:GetService("Players")
local Tool = script.Parent
local ServerEvent = Tool:WaitForChild("OnFired")
ServerEvent.OnServerEvent:Connect(function(Player, MousePosition, Target)
print(Target)
local FoundPlayer = Players:GetPlayerFromCharacter(Target.Parent) -- returns either a Player or nil
if typeof(Target) == "Instance" and FoundPlayer then
local Character = FoundPlayer.Character -- the player's character
print(Target.Parent.Name)
end
end)
--//Services
local Players = game:GetService("Players")
--//Variables
local Tool = script.Parent
local ServerEvent = Tool:WaitForChild("OnFired")
--//Functions
ServerEvent.OnServerEvent:Connect(function(Player, MousePosition, Target)
local TargetPlayer = Players:GetPlayerFromCharacter(Target.Parent)
if TargetPlayer then
local Character = TargetPlayer.Character
print(TargetPlayer.Name, "is the target.")
end
end)
Target can be named anything, for example if you do
ServerEvent:FireServer(MousePos,Target)
it will get the mouse pos and the player target for the server sided when u call it SO when u get it you will see player just ignore it’s needed to get the actual player not the character, to get what you get from the client fire server its the same order just ignore the “Player” You can name it anything and it will get the MousePos and Target.
I don’t know, the person who sent it to me didnt explain everything through. I should have rewritten it but I am super confused on getting the mouse’s position that i just need something that works
FindFirstAncestorWhichIsA(“Model”) will tell you if the hit part is part of a model. If the model contains a humanoid and Players:GetPlayerFromCharacter(OtherModel) returns a player, it is a player character
-- Finds if the touched part is part of a model
-- For parts that are not part of a model, this will return as Workspace
local OtherModel = OtherPart:FindFirstAncestorWhichIsA("Model")
-- If the touched model exists and contains a humanoid (living creature)
if OtherModel and OtherModel ~= game.Workspace and OtherModel:FindFirstChildWhichIsA("Humanoid") then
-- If the hit model is a player character
local Victim = Players:GetPlayerFromCharacter(OtherModel)
if Victim then
-- A player character has been hit
end
end
I am trying to damage the player but i need the character first, which i used hitcast to get the player, and i didnt know how, i asked a server but they werent any help they just gave me gibberish and I dont even know where i started
Sorry if my posts aren’t ‘useful’ so far, I am just struggling to understand what you’re doing. You just gave us the server part, but we don’t know what you’re doing on the client…