Issue with script

–ok so run this and if its only printing the plr name that you are hitting then this works, but if it print ur name then it doesn’t work.

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 == game.Players.LocalPlayer.Name then return else end

print(Hit.Parent.Humanoid.Parent.Name)
			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)

image

Hmm ok ok, instead of print(Hit.Parent.Humanoid.Parent.Name)
Replace it with just print(Hit.Parent.Name)

image

script.Parent:WaitForChild("Hitbox").Touched:Connect(function(Hit)
	if Swinging then
		if Hit.Parent.Name ~= Character.Name then
			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
end)

Try this maybe?

Doesn’t work sadly, just ragdolls me.
image

What are you hitting? Bc the error is saying what ever you are hitting Doesn’t have a Humanoid.

I am hitting the hitbox, please read the script.

script.Parent:WaitForChild("Hitbox").Touched:Connect(function(Hit)

No i mean is there a real player that you are hitting or is it a rig

IIt is infact a real player, as I am testing with my friend.

Can I see your ragdoll onServerEvent?

How does it know which player it will ragdoll? According to the above line of of code, you sent a string value as a parameter, but not the player that you hit?

3 Likes
game.ReplicatedStorage.Core.Events.Ragdoll.Manager.OnServerEvent:Connect(function(target,state)
	if state ~= "ragdoll" or state ~= "unragdoll" then
		print(state)
		wait(0.01)
		state = "ragdoll"
		print(target)
		RagdollClient:FireAllClients(target,state)
	elseif state == "hitboxclient" then
		game.ReplicatedStorage.Core.Events.Ragdoll.HitboxClient:FireAllClients(target,state)
	end
end)

The ragdoll code:

local RagdollServer = game.ReplicatedStorage.Core.Events.Ragdoll
local RagdollClient = game.ReplicatedStorage.Core.Events.Ragdoll.RagdollClient



RagdollClient.OnClientEvent:Connect(function(target,state)
	if state == "ragdoll" then
		print(target)
		local char = target.Character
		local humanoid = char.Humanoid
		humanoid.BreakJointsOnDeath = false
		humanoid.RequiresNeck= false
		humanoid:ChangeState(Enum.HumanoidStateType.Physics)
		RagdollServer:FireServer(char,state)
		
		
	elseif state == "unragdoll" then
		local char = target.Character
		local humanoid = char.Humanoid
		humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
		humanoid.BreakJointsOnDeath = true
		humanoid.RequiresNeck = true
		RagdollServer:FireServer(char,state)
	else
		warn("lol  | state not found " .. tostring(state))
	end
end)


Ah I see…

the OnServerEvent has the player who sent it as the first parameter. Hence, why the person who use the tool is ragdolled.

Fix:

(Local Script)

local Players = game:GetService("Players")
local Target = Players:GetPlayerFromCharacter(Hit.Parent)

game.ReplicatedStorage.Core.Events.Ragdoll.Manager:FireServer(Target,"ragdoll")

(ServerScript)

game.ReplicatedStorage.Core.Events.Ragdoll.Manager.OnServerEvent:Connect(function(player,target,state)

This should fix it, let me know if I miss something.

1 Like

Nope, does not work.
Tried it on my alt (myse,f and my alt on a game) nothing worked.
ALL OF MY CODE.

Inside the tool > local script

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
local debounce = false

function target(t,Humanoid)
	local targetPlayer = game.Players:FindFirstChild(t)
	Humanoid = targetPlayer.Character.Humanoid
	if targetPlayer == game.Players.LocalPlayer then
		return nil
	else
		game.ReplicatedStorage.Core.Events.Ragdoll.Manager:FireServer(target,"hitboxclient")
	end
end

script.Parent:WaitForChild("Hitbox").Touched:Connect(function(Hit)
	if Swinging then
		local hitter = stick.Parent
		local Char = nil
		local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
		local HitParent = Hit.Parent
		local targeted = game.Players:GetPlayerFromCharacter(HitParent)

		if Hit.Parent.Parent == hitter then
			print("cannot ragdoll yourself, lol")
		elseif not Hit.Parent.Parent == game.Players.LocalPlayer then
			local Target = Players:GetPlayerFromCharacter(Hit.Parent)
			game.ReplicatedStorage.Core.Events.Ragdoll.Manager:FireServer(Target,"ragdoll")
		else
			print("oop")
		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
	SwingAnim:Stop()
end)

stick.Activated:Connect(function()
	if debounce == false then
		SwingAnim:Play()
		Swinging = true
		debounce = true
		Swinging = false
		wait(3)
		debounce = false
	end
end)

Ragdoll client > Local script
local RagdollServer = game.ReplicatedStorage.Core.Events.Ragdoll
local RagdollClient = game.ReplicatedStorage.Core.Events.Ragdoll.RagdollClient

RagdollClient.OnClientEvent:Connect(function(target,state)
	if state == "ragdoll" then
		print(target)
		local char = target.Character
		local humanoid = char.Humanoid
		humanoid.BreakJointsOnDeath = false
		humanoid.RequiresNeck= false
		humanoid:ChangeState(Enum.HumanoidStateType.Physics)
		RagdollServer:FireServer(char,state)
		
		
	elseif state == "unragdoll" then
		local char = target.Character
		local humanoid = char.Humanoid
		humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
		humanoid.BreakJointsOnDeath = true
		humanoid.RequiresNeck = true
		RagdollServer:FireServer(char,state)
	else
		warn("lol  | state not found " .. tostring(state))
	end
end)

local RagdollServer = game.ReplicatedStorage.Core.Events.Ragdoll
local RagdollClient = game.ReplicatedStorage.Core.Events.Ragdoll.RagdollClient



RagdollClient.OnClientEvent:Connect(function(target,state)
	if state == "ragdoll" then
		print(target)
		local char = target.Character
		local humanoid = char.Humanoid
		humanoid.BreakJointsOnDeath = false
		humanoid.RequiresNeck= false
		humanoid:ChangeState(Enum.HumanoidStateType.Physics)
		RagdollServer:FireServer(char,state)
		
		
	elseif state == "unragdoll" then
		local char = target.Character
		local humanoid = char.Humanoid
		humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
		humanoid.BreakJointsOnDeath = true
		humanoid.RequiresNeck = true
		RagdollServer:FireServer(char,state)
	else
		warn("lol  | state not found " .. tostring(state))
	end
end)

Ragdoll Server

local RagdollServer = game.ReplicatedStorage.Core.Events.Ragdoll
local RagdollClient = game.ReplicatedStorage.Core.Events.Ragdoll.RagdollClient

RagdollServer.OnServerEvent:Connect(function(player,character,state)
	
	if state == "ragdoll" then
		print(state)
		for _, v in pairs(character:GetDescendants()) do  --ragdoll
			if v:IsA("Motor6D") then
				local a0, a1 = Instance.new("Attachment"), Instance.new("Attachment")
				a0.CFrame = v.C0
				a1.CFrame = v.C1
				a0.Parent = v.Part0
				a1.Parent = v.Part1
				local b = Instance.new("BallSocketConstraint")
				b.Attachment0 = a0
				b.Attachment1 = a1
				b.Parent = v.Part0
				v.Enabled = false
			end
		end
	elseif state == "unragdoll" then
		print(state)
		for _,v in pairs(character:GetDescendants()) do  --unragdoll
			if v:IsA('Motor6D') then
				v.Enabled = true
			end
			if v.Name == 'BallSocketConstraint' then
				v:Destroy()
			end
			if v.Name == 'Attachment' then
				v:Destroy()
			end
			RagdollClient:FireClient(player)
		end
	end
end)


game.ReplicatedStorage.Core.Events.Ragdoll.Manager.OnServerEvent:Connect(function(player,target,state)
	if state ~= "ragdoll" or state ~= "unragdoll" then
		print(state)
		wait(0.01)
		state = "ragdoll"
		print(target)
		RagdollClient:FireAllClients(target,state)
	elseif state == "hitboxclient" then
		game.ReplicatedStorage.Core.Events.Ragdoll.HitboxClient:FireAllClients(target,state)
	end
end)

I think Hit.Parent should be enough. If it hits the RightArm for example, the parent of the RightArm is the character, so that is Hit.Parent. if Hit.Parent.Parent then it means the workspace, or the parent of the character. Plus, you already have a variable set for the Hit.Parent which is “HitParent”.

After you replace the Hit.Parent.Parent to HitParent, change the hitter and game.Players.LocalPlayer to “hitter” or “Character”

There might be other factors for it to not work, can you help? @kevine8854

This is getting long… and I got late, and I really dont understand what approach you are trying.
Analize those scripts step by step could be useless if we dont understand the exact mechanics you are following.
Its just, A player attack someone with a tool, the “victim” get ragdolled, and your server gets whos the “Killer” and who’s the “victim” ?
The exact procedure you are following?

It says it in my original post - please read it,

I am creating a system where you hit someone with a tool, they ragdolled.
The ragdoll side works, it’s getting the player not the actual ragdoll functions.

If the ragdoll side works, it is probably a logic problem. Check your variables. Make sure it refers precisely what it means to. For easier debugging, print everytime an event is fired to check which one doesn’t. Make sure the print is unique so that you can identify the exact part that didnt run or run incorrectly. That is all I can help.

You already getting/sending the plr char

So i think here is also a mistake

Bc you cant get a char from a char

I would suggest replying

To

local char = target