Whenever the player Jumps it should unweld the part and weld it after. Although, it certainly works I’m having an issue which it only affects a single player. I’ve tried to put the script onto the PlayerAdded event but to no avail.
Local script:
local player = game.Players.LocalPlayer
local RS = game:GetService("ReplicatedStorage")
local unweldPartFunction = RS:WaitForChild("UnweldPartFunc")
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.Space then
unweldPartFunction:FireServer()
end
end)
Script:
local RS = game:GetService("ReplicatedStorage")
local unweldPartFunction = RS:WaitForChild("UnweldPartFunc")
game.Players.PlayerAdded:Connect(function(player)
local charac = player.CharacterAdded:Wait()
head = charac:WaitForChild("Head")
part = Instance.new("Part", game.Workspace.PartsOnHead)
part.Name = "partonhead"
part.CFrame = head.CFrame * CFrame.new(0,2,0) -- Sets the Position above the head
weld = Instance.new("WeldConstraint") -- welds the item and the head
weld.Part0 = head
weld.Part1 = part
weld.Parent = head
end)
unweldPartFunction.OnServerEvent:Connect(function(player)
part.Anchored = true
weld.Enabled = false
wait(2)
part.CFrame = head.CFrame * CFrame.new(0,2,0)
part.Anchored = false
weld.Enabled = true
end)
I think you should SetNetworkOwner to the client then enable/disable the “PartWeld” from there. Check this out!
--[[CLIENT]]--
local Players = game:GetService('Players')
local UserInputService = game:GetService('UserInputService')
--
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild('Humanoid')
local Head = Character:WaitForChild('Head')
local WeldedPart = Head:WaitForChild('WeldedPart')
local PartWeld = WeldedPart:WaitForChild('PartWeld')
--
function OnBeganInputs (Input, GameProcessed)
if GameProcessed then
return
end
if (Input.KeyCode == Enum.KeyCode.Space) then
PartWeld.Enabled = false
WeldedPart.Anchored = true
wait(2)
WeldedPart.Anchored = false
PartWeld.Enabled = true
end
end
--
UserInputService.InputBegan:Connect(OnBeganInputs)
--[[SERVER]]--
local Players = game:GetService('Players')
--
local function OnPlayerAdded (Player)
local function OnCharacterAdded (Character)
local Head = Character:WaitForChild('Head')
--
local WeldedPart do
WeldedPart = Instance.new('Part')
WeldedPart.Name = 'WeldedPart'
WeldedPart.Size = Vector3.new(2,1,1)
WeldedPart.Material = Enum.Material.SmoothPlastic
WeldedPart.BrickColor = BrickColor.new('Grey')
WeldedPart.Parent = Head
end
local PartWeld do
PartWeld = Instance.new('Weld')
PartWeld.Name = 'PartWeld'
PartWeld.Part0 = WeldedPart
PartWeld.Part1 = Head
PartWeld.C0 = CFrame.new(0,-(Head.Size.Y/2 + WeldedPart.Size.Y/2),0)
PartWeld.Parent = WeldedPart
end
--
WeldedPart:SetNetworkOwner(Player)
end
--
OnCharacterAdded(Player.Character or Player.CharacterAdded:Wait())
--
Player.CharacterAdded:Connect(OnCharacterAdded)
end
--
Players.PlayerAdded:Connect(OnPlayerAdded)