Hello im trying to make a “pole swing” mechanic in where you get attached to a part, jump to break the attachment and get a slight jump boost after that
It works most of the time, except when it decides to break itself for some reason… with "Workspace.Bar.Bar.Script:7: attempt to index nil with ‘Character’ " (and in-game which for some reason the jump boost doesnt work)
Server Side Script (is attached to the part)
local part = script.Parent
local debounce = false
local function weldPlayer(player)
local character = player.Character
local rootPart = character and character:FindFirstChild("HumanoidRootPart")
if character and rootPart then
local weld = Instance.new("WeldConstraint")
weldObject = Instance.new("ObjectValue")
weld.Part0 = part
weld.Part1 = rootPart
weld.Parent = part
weldObject.Parent = character.HumanoidRootPart
weldObject.Name = "WeldIsTrue"
character.Humanoid.PlatformStand = false
character.HumanoidRootPart.CanCollide = false
print("is this working?")
local sound = Instance.new("Sound", character)
sound.SoundId = "rbxassetid://12222140"
sound:Play()
end
end
part.Touched:Connect(function(hit)
if debounce == false then
debounce = true
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
weldPlayer(player)
game.ReplicatedStorage.Test.OnServerEvent:Connect(function()
if part:FindFirstChild("WeldConstraint") then
print("fired the RemoteEvent")
print("success")
part.WeldConstraint:Destroy()
weldObject:Destroy()
wait(3)
debounce = false
end
end)
end
end)
Client Side Script (is inside StarterCharacterScripts)
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Bar = script.Parent.HumanoidRootPart
local remoteEvent = game.ReplicatedStorage.Test
UserInputService.InputBegan:Connect(function(input, event)
if input.KeyCode == Enum.KeyCode.Space then
if script.Parent.HumanoidRootPart:FindFirstChild("WeldIsTrue") then
remoteEvent:FireServer()
task.wait(0.1)
if script.Parent:FindFirstChild('Humanoid') ~= nil then
print("boing")
script.Parent.HumanoidRootPart:ApplyImpulse(Vector3.new(0, 1000, 0))
end
end
end
end)
Any idea what causes this to break? And why it when in-game (in testing works fine) the impulse doesnt work? Any help will be appreciated!