Script works normally when in workspace but not when I clone it?

apologies if the title made no sense, here’s a longer description of my problem. So I have a part that ragdolls players when they touch it, it works properly when it’s just placed in the workspace but when I use code to clone the part and place it where player is, the ragdoll stops working and gives me this error: FireClient: player argument must be a Player object

here’s the module script that errors:

local RagdollFunctions = {}

RagdollFunctions.Ragdoll = function(random, char, player) -- this line errors
	
	game.ReplicatedStorage.RagdollEvent:FireClient(player, "Ragdoll") -- fire an event to the client
	
	char.Humanoid.JumpPower = 0 -- make sure they cant jump
	
	for _, v in pairs(char:GetDescendants()) do
		if v:IsA("BasePart") and v.Name == "Head" or v:IsA("BasePart") and v.Name == "LowerTorso" then			local weld = Instance.new("Weld")
			weld.Part0 = char.HumanoidRootPart
			weld.Part1 = v
			weld.C0 = char.HumanoidRootPart.CFrame:Inverse()
			weld.C1 = v.CFrame:Inverse()
			weld.Parent = char.HumanoidRootPart
		end
		
		if v:IsA("Motor6D") then
			local attachment0 = Instance.new("Attachment")
			local attachment1 = Instance.new("Attachment")
			
			attachment0.Name = "Attachment0"
			attachment1.Name = "Attachment1"
			
			attachment0.CFrame = v.C0
			attachment1.CFrame = v.C1
			attachment0.Parent = v.Part0
			attachment1.Parent = v.Part1
			
			local constraint = Instance.new("HingeConstraint")
			
			constraint.Attachment0 = attachment0
			constraint.Attachment1 = attachment1
			constraint.Parent = v.Part0
			
			v:Destroy()
		end
	end
	
end



RagdollFunctions.Stand = function(random, char, player, humanoid) -- standing function
	
	humanoid.JumpPower = 50
	
	for _, v in pairs(char:GetDescendants()) do
		if v.Name == "Attachment0" or v.Name == "Attachment1" or v:IsA("Weld") or v:IsA("HingeConstraint") then 
			v:Destroy()
		end
	end
	
	humanoid:BuildRigFromAttachments() -- very handy function
	
	game.ReplicatedStorage.RagdollEvent:FireClient(player, "Stand")
	
end



return RagdollFunctions

all help is appreciated!

Player argument must be player.

Where is this function called? Check if you are passing a player as the third argument of RagdollFunctions.Ragdoll.

the function is called to a script inside of the part which actually ragdolls the player. I’ve used this ragdoll before and it has worked but for some reason it’s not working now?

here’s the script where the function is called:

local delay = false -- adding a delay
local RagdollModule = require(game.ReplicatedStorage.RagdollScript)

script.Parent.Touched:Connect(function(hit) -- fires when the player touches the part
	if delay == false then
		if hit.Parent then
			if hit.Parent:FindFirstChild("Humanoid") then -- making sure the player is not an object
				delay = true
				
				local char = hit.Parent 
				local player = game:GetService("Players"):GetPlayerFromCharacter(char)
				
				RagdollModule:Ragdoll(char, player) -- activating the ragdoll
				
				wait(10) -- how long they ragdoll
				
				RagdollModule:Stand(char, player, char.Humanoid) -- standing the player up
				
				wait(2) -- adding a delay for the ragdoll
				
				delay = false
			end
		end
	end
end)

The problem doesn’t seem to be within the function itself, but instead how you call it. When you call it you need to put in a player object in the 3rd argument, but you’ve put something else in.

1 Like

There are only 2 arguments here, whereas the function takes 3 arguments with char as second and player as the third.

let me try adding the first argument and see it works. I believe that could be the solution

edit: it worked perfectly, thanks so much!