Hi, so basically I am creating a system where you hit someone with a tool, they ragdoll & the ragdoll side works it’s the actual getting the players humanoid & that stuff. At the moment, it will get my humanoid (person who’s holding the sword) instead of someone else, even THOUGH i have added statements to prevent that.
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local RepStorage = game:GetService("ReplicatedStorage")
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Swinging = true
local HittedRegion = {}
local Stick = script.Parent
script.Parent:WaitForChild("Hitbox").Touched:Connect(function(Hit)
if Swinging then
local hitter = game.Players.LocalPlayer.Name
local Char = nil
local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
local HitParent = Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent or (Hit.Parent.Parent:FindFirstChild("Humanoid") and Hit.Parent.Parent or nil)
local targeted = game.Players:GetPlayerFromCharacter(HitParent)
if targeted == hitter then
print("cannot ragdoll yourself, lol")
else
game.ReplicatedStorage.Core.Events.Ragdoll.Manager:FireServer("ragdoll")
end
end
end)
local Ready = false
local SwingAnim = Character:WaitForChild("Humanoid"):LoadAnimation(Stick:WaitForChild("Swing"))
Stick.Equipped:Connect(function()
Ready = true
while true do
wait(0.1)
script.Parent.Hitbox.Position = script.Parent.Handle.Position
end
end)
Stick.Unequipped:Connect(function()
Ready = false
script.Parent.Swing:Stop()
end)
Stick.Activated:Connect(function()
SwingAnim:Play()
print(" - loader")
end)
2 Likes
Hi - I am currently still experiencing issues w/ this and have tried over 4 different methods.
The issue is that you’re checking if the Humanoid that was hit is equivalent to the LocalPlayer’s Username. Add .Name
to the if condition for targeted
.
Also, I don’t recommend marking your reply as a solution because it’ll make people think that the issue has been solved
1 Like
Having issues again, basically it will still do the local player & not hit.Parent
You’re script that I tried, came w/ this.
No because, it needs to get the .Hit event from the .Touched event.
System does work, though it isn’t getting the player that IS getting hit.
script.Parent:WaitForChild("Hitbox").Touched:Connect(function(Hit)
if Swinging == true then
local hitter = game.Players.LocalPlayer.Name
local Char = nil
local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
local HitParent = Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent or (Hit.Parent.Parent:FindFirstChild("Humanoid") and Hit.Parent.Parent or nil)
local target = HitParent
if not Hit.Parent == hitter then
game.ReplicatedStorage.Core.Events.Ragdoll.Manager:FireServer(Hit.Parent,"ragdoll")
else
print("Cannot Hit Yourself")
end
end
end)
Yes you can.
You can use it in a server and local script.
char = Character, meaning that it’s the targets character
& it gets used in another system
Still confused … I’m really confused at this point.
and how would I fix this issue?
Try see if this works…
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local RepStorage = game:GetService("ReplicatedStorage")
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Swinging = true
local HittedRegion = {}
local Stick = script.Parent
script.Parent:WaitForChild("Hitbox").Touched:Connect(function(Hit)
if Swinging then
if Hit.Parent.Name == LocalPlayer.Name then return else end
local hitter = game.Players.LocalPlayer.Name
local Char = nil
local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
local HitParent = Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent or (Hit.Parent.Parent:FindFirstChild("Humanoid") and Hit.Parent.Parent or nil)
local targeted = game.Players:GetPlayerFromCharacter(HitParent)
game.ReplicatedStorage.Core.Events.Ragdoll.Manager:FireServer("ragdoll")
end
end)
local Ready = false
local SwingAnim = Character:WaitForChild("Humanoid"):LoadAnimation(Stick:WaitForChild("Swing"))
Stick.Equipped:Connect(function()
Ready = true
while true do
wait(0.1)
script.Parent.Hitbox.Position = script.Parent.Handle.Position
end
end)
Stick.Unequipped:Connect(function()
Ready = false
script.Parent.Swing:Stop()
end)
Stick.Activated:Connect(function()
SwingAnim:Play()
print(" - loader")
end)
Nope, does not work, sadly.
Will hopefully figure a new solution soon
No, it’s still broken.
It’s still as before.
no because it prints their username
ive been working at this for 9 hours, i’m really tired it’s 3am and all im looking is for a solution.
I’m quite delusional and weary so I honestly do not know
Where is this local script located?
inside the tool which is located in serverstorage.
no, I printed the target, as you can see IN my script.
Sadly, does not work.
Not sure.