I checked over this script so many times! It still won’t seem to work!
This is a leaderstat script for my drag simulator. It won’t appear in game.
Please check over this script and respond to what I did wrong below!
events = game.ReplicatedStorage.Events
dragEvent = events.Drag
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder", plr)
leaderstats.Name = "leaderstats"
local kills = Instance.new("IntValue", leaderstats)
kills.Name = "Kills"
kills.Value = 0
local role = Instance.new("StringValue", leaderstats)
role.Name = "Rank"
role.Value = plr:GetRoleInGroup(6633354)
plr.CharacterAdded:connect(function(char)
repeat wait() until char:FindFirstChild("Humanoid")
char.Humanoid.WalkSpeed = 32
local d = Instance.new("BoolValue", plr.Character)
d.Name = "Dragging"
d.Value = false
local ld = Instance.new("StringValue", plr.Character)
ld.Name = "LastDraggedBy"
ld.Value = ""
char:WaitForChild("Humanoid").Died:connect(function()
if char:FindFirstChild("Dragged") or char:FindFirstChild("LastDraggedBy") then
if game.Players:FindFirstChild(char.LastDraggedBy.Value) then
unweld(plr, game.Players[char.LastDraggedBy.Value])
game.Players[char.LastDraggedBy.Value].leaderstats.Kills.Value = game.Players[char.LastDraggedBy.Value].leaderstats.Kills.Value + 1
end
end
end)
--[[plr.CharacterRemoving:connect(function(char)
if char:FindFirstChild("Dragged") then
if game.Players:FindFirstChild(char.Dragged.Value) then
game.Players[char.Dragged.Value].leaderstats.Kills.Value = game.Players[char.Dragged.Value].leaderstats.Kills.Value + 1
end
end
end)]]
end)
end)
function ropeSound(rope)
if rope then
local s = game.ReplicatedStorage.Sounds:WaitForChild(“Boing”):Clone()
s.Parent = rope
s:Play()
spawn(function()
repeat wait() until s.IsPaused()
s:Destroy()
end)
end
end
function createDebounce(vic, plr)
local d = Instance.new(“StringValue”, vic.Character)
d.Name = “Dragged”
d.Value = plr.Name
plr.Character.Dragging.Value = true
end
function removeDebounce(vic, plr)
local d = vic.Character:FindFirstChild(“Dragged”)
if plr.Character and plr.Character:FindFirstChild(“Dragging”) then
plr.Character.Dragging.Value = false
end
if d then
d:Destroy()
end
end
function loopSit(vic)
spawn(function()
while vic.Character and vic.Character:FindFirstChild(“Humanoid”) and vic.Character:FindFirstChild(“Dragged”) and vic.Character:FindFirstChild(“Dragging”).Value == false do
if vic.Character:FindFirstChild(“Humanoid”) then
wait()
vic.Character.Humanoid.PlatformStand = true
else
break
end
end
if vic.Character and vic.Character:FindFirstChild(“Humanoid”) then
vic.Character.Humanoid.PlatformStand = false
end
end)
end
function weld(victim, plr)
loopSit(victim)
plr.Character.Dragging.Value = true
plr.Character.Humanoid.WalkSpeed = 32
victim.Character.Humanoid.WalkSpeed = 0
–[[victim.Character.Humanoid.UseJumpPower = false
wait()
victim.Character.Humanoid.JumpPower = 0
victim.Character.Humanoid.JumpHeight = 0]]
local weld = Instance.new(“RopeConstraint”, plr.Character)
ropeSound(weld)
weld.Enabled = true
weld.Visible = true
weld.Restitution = 0.5
weld.Length = 9
weld.Name = victim.Name
local at1 = Instance.new(“Attachment”)
at1.Parent = plr.Character.HumanoidRootPart --or plr.Character:FindFirstChild(“RightHand”)
local at2 = Instance.new(“Attachment”, victim.Character.HumanoidRootPart)
weld.Attachment0 = at1
weld.Attachment1 = at2
–victim.Character:FindFirstChild(“HumanoidRootPart”).Position = plr.Character:FindFirstChild(“HumanoidRootPart”).Position + Vector3.new(0,0,3)
print(“welded”)
end
function unweld(victim, plr)
if victim ~= nil and plr ~= nil then
if plr.Character:FindFirstChild(victim.Name) then
plr.Character[victim.Name]:Destroy()
end
if plr.Character:FindFirstChild(“Dragging”) then
plr.Character.Dragging.Value = false
end
if victim.Character:FindFirstChild(“Dragging”) then
victim.Character.Dragging.Value = false
end
if victim.Character:FindFirstChild(“Dragged”) then
victim.Character.Dragged:Destroy()
end
plr.Character.Humanoid.WalkSpeed = 32
victim.Character.Humanoid.WalkSpeed = 32
plr.Character.Humanoid.PlatformStand = false
victim.Character.Humanoid.PlatformStand = false
–wait(0.5)
–victim.Character.Humanoid.UseJumpPower = true
print(“unwelded”)
end
end
function bringTogether(plr, ty, victim)
if plr.Character and victim ~= nil and game.Players:FindFirstChild(plr.Name) and game.Players:FindFirstChild(victim.Name) then
if ty == “Drag” then
if plr.Character:FindFirstChild(“HumanoidRootPart”) and victim.Character:FindFirstChild(“HumanoidRootPart”) and not victim.Character:FindFirstChild(“Dragged”) and not victim.Character:FindFirstChild(plr.Name) and victim.Character.Dragging.Value == false and not plr.Character:FindFirstChild(“Dragged”) and plr.Character.Dragging.Value == false then
if (victim.Character.HumanoidRootPart.Position - plr.Character.HumanoidRootPart.Position).magnitude < 8 and victim.Character.Humanoid.Health > 1 and plr.Character.Humanoid.Health > 1 then
victim.Character.LastDraggedBy.Value = plr.Name
createDebounce(victim, plr)
–[[spawn(function()
repeat wait() until not victim.Character or victim.Character:FindFirstChild(“Humanoid”).Health < 1
end)]]
–victim.Character:BreakJoints()
weld(victim, plr)
else
warn("EXCEEDING DISTANCE: "…plr.Name)
end
end
elseif ty == “Undrag” then
print("trying to undrag from: ", plr)
if plr.Character and victim.Character and plr.Character:FindFirstChild(“HumanoidRootPart”) and victim.Character:FindFirstChild(“HumanoidRootPart”) and victim.Character:FindFirstChild(“Dragged”) and plr.Character.Dragging.Value == true then
removeDebounce(victim, plr)
unweld(victim, plr)
end
end
end
end
dragEvent.OnServerEvent:connect(bringTogether)