Heya! I have been creating emotes for my new game, and I’ve come across an issue that seems like I cannot solve.
I have this script in workspace within a folder:
local instances
local r6Anim = Instance.new("Animation")
local r15Anim = Instance.new("Animation")
r6Anim.AnimationId = "rbxassetid://11218119404"
r15Anim.AnimationId = "rbxassetid://11215798933"
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local function onPlayerAdded(player)
local function onCharacterAdded(character)
local humanoid = character:WaitForChild("Humanoid")
local function onDied()
game.ReplicatedStorage.PlayerData[player.Name]:WaitForChild("Dancing").Value = false
local rag = require(game.ReplicatedStorage.Rag)
rag:Fire(player.Character)
end
humanoid.Died:Connect(onDied)
end
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)
game.Players.PlayerAdded:Connect(function(player)
local track
player.Chatted:Connect(function(msg)
if msg:lower() == "/slumber" then
if MarketplaceService:UserOwnsGamePassAsync(player.UserId, 92444813) then
if game.ReplicatedStorage.PlayerData[player.Name]:WaitForChild("Dancing").Value == true then
return
end
if player.Character.Humanoid.RigType == Enum.HumanoidRigType.R15 then
game.ReplicatedStorage.Events.Notify:FireClient(player,nil,"notavailable")
return
end
game.ReplicatedStorage.PlayerData[player.Name]:WaitForChild("Dancing").Value = true
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://11218048803"
sound.Parent = player.Character.Head
sound.Volume = .3
sound.RollOffMaxDistance = 50
sound.Looped = true
sound:Play()
local rag = require(game.ReplicatedStorage.Rag)
rag:Fire(player.Character)
else
local ReplicatedStorage = game:GetService("ReplicatedStorage")
ReplicatedStorage.Events.Notify:FireClient(player,nil,"notavailable")
end
end
end)
game.ReplicatedStorage.Events.Jumped.OnServerEvent:Connect(function()
if game.ReplicatedStorage.PlayerData[player.Name]:WaitForChild("Dancing").Value == true then
game.ReplicatedStorage.PlayerData[player.Name]:WaitForChild("Dancing").Value = false
player.Character.Head.Sound:Destroy()
local rag = require(game.ReplicatedStorage.Rag)
rag:Fire(player.Character)
end
end)
end)
and this module in replicated storage:
local module = {}
local ps = game:GetService("PhysicsService")
local colGroup = "No Collision Group " .. tostring(math.random(0, 10000))
local noTouchGroup = ps:CreateCollisionGroup(colGroup)
ps:CollisionGroupSetCollidable(colGroup, colGroup, false)
function module:Ragdoll(character)
if character == nil and character:FindFirstChildWhichIsA("Humanoid") then return end
local hum = character:FindFirstChildWhichIsA("Humanoid")
if hum ~= nil then
hum.PlatformStand = true
hum.RequiresNeck = false
end
local jointFolder = Instance.new("Folder", character)
jointFolder.Name = "RagdollJointsFolder"
local collisionFolder = Instance.new("Folder", character)
collisionFolder.Name = "RagdollCollisionsFolder"
for _, x in pairs(character:GetDescendants()) do
if x:IsA("BasePart") then
x:SetAttribute("OriginalCollisionGroupId", x.CollisionGroupId)
x.CollisionGroupId = noTouchGroup
local collision = x:Clone()
collision.CollisionGroupId = noTouchGroup
collision.Name = "Collision"
collision.CanCollide = true
collision:ClearAllChildren()
collision.Transparency = 1
collision:BreakJoints()
local weld = Instance.new("Weld", collision)
weld.Name = "CollisionWeld"
weld.Part0 = collision
weld.Part1 = x
collision.Parent = collisionFolder
end
if x:IsA("Motor6D") and x.Part1 ~= nil and x.Part0 ~= nil and x.Enabled == true and x.Part1.Transparency ~= 1 and x.Part0.Transparency ~= 1 then
local attch = Instance.new("Attachment", x.Part1)
attch.Name = x.Name .. " Joint"
attch.CFrame = x.C1
local attch2 = Instance.new("Attachment", x.Part0)
attch2.Name = x.Name .. " Main"
attch2.CFrame = x.C0
--attch2.WorldCFrame = attch.WorldCFrame
local sock = Instance.new("BallSocketConstraint", attch)
sock.Attachment0 = attch
sock.Attachment1 = attch2
sock.LimitsEnabled = true
sock.MaxFrictionTorque = 1
sock.UpperAngle = 45
sock.TwistLimitsEnabled = true
sock.TwistLowerAngle = -22.5
sock.TwistUpperAngle = 22.5
local attVal = Instance.new("ObjectValue", jointFolder)
attVal.Name = x.Name
attVal.Value = x
local attVal2 = Instance.new("ObjectValue", attVal)
attVal2.Name = "Main"
attVal2.Value = attch
local attVal3 = Instance.new("ObjectValue", attVal)
attVal3.Name = "Joint"
attVal3.Value = attch2
x.Enabled = false
end
end
end
function module:UnRagdoll(character)
local fol = character:FindFirstChild("RagdollJointsFolder")
local fol2 = character:FindFirstChild("RagdollCollisionsFolder")
local hum = character:FindFirstChildWhichIsA("Humanoid")
if hum ~= nil then
hum.PlatformStand = false
end
if fol then
for _, x in pairs(fol:GetChildren()) do
if x.Value ~= nil and x.Value.Parent ~= nil then
x.Value.Enabled = true
end
if x.Main.Value ~= nil and x.Main.Value.Parent ~= nil then
x.Main.Value:Destroy()
end
if x.Joint.Value ~= nil and x.Joint.Value.Parent ~= nil then
x.Joint.Value:Destroy()
end
end
fol:Destroy()
end
if fol2 then
for _, x in pairs(fol2:GetChildren()) do
if x:FindFirstChild("CollisionWeld") then
local originalCollision = x:GetAttribute("OriginalCollisionGroupId") or x.CollisionGroupId
x.CollisionWeld.Part1.CollisionGroupId = originalCollision
end
end
fol2:Destroy()
end
end
function module:Fire(p, ragdoll)
if p == nil then return end
local character = p
if p:IsA("Player") then
character = p.Character
end
if character == nil then return end
if ragdoll ~= true and (character:FindFirstChild("RagdollJointsFolder") ~= nil or character:FindFirstChild("RagdollCollisionsFolder") ~= nil) then
module:UnRagdoll(character)
elseif ragdoll ~= false then
module:Ragdoll(character)
end
return noTouchGroup
end
return module
The event is fired by this simple local script in starterplayerscripts:
local UserInt = game:GetService("UserInputService")
UserInt.InputBegan:Connect(function(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.Space then
if game.ReplicatedStorage.PlayerData[game.Players.LocalPlayer.Name].Dancing.Value == true then
print("true")
game.ReplicatedStorage.Events.Jumped:FireServer()
end
end
end)
and when the player jumps, it is supposed to unragdoll as intended. (rag:Fire(player.Character)
)
but it doesn’t?
I do not see a problem and maybe you will. The audio does get removed as intended, it just does not unragdoll.