I’ve been trying to make a client-sided kicking system for decorative objects that have a specific tag.
(Example: Kickable cups on a table.)
Once the part is touched by the player’s leg, it becomes kicked & body velocity flings it in the player’s direction, it de-spawns after 3 seconds. (This is done through a local script in StarterCharacterScripts.)
The issue with this is that once the part is unanchored, it moves like it’s supposed to for half a second & just completely freezes. What’s weird is that it works fine if it’s unanchored from the start, but if I do that, it’ll be kicking on the server’s side.
I’ve looked around on the Devfourm but I’m still very confused about the issue. I don’t know if it’s the part “sleeping”, if it’s a network ownership thing, or if it’s something completely different.
This is the code that I’m working with at the moment. Any help would be appreciated!
local CollectionService = game:GetService("CollectionService")
--// KICKABLES
for i, KICK in pairs(CollectionService:GetTagged("Kickable")) do
local event = game.ReplicatedStorage.Events.KickEvent
local respawnTimer = 3
local kicked = false
local debris = game:GetService("Debris")
local ts = game:GetService("TweenService")
KICK.CollisionGroup = "noPlrs"
--// THE DESPAWNING
local function despawnPart(target)
local fade = ts:Create(target, TweenInfo.new(1), {Transparency = 1})
task.wait(respawnTimer)
fade:Play()
task.wait(1)
target:Destroy()
end
--// THE FUNCTIONING
local function kick(target)
local dir = CFrame.lookAt(rp.Position, target.Position).LookVector
if dir.Magnitude < 0.001 then
return
end
--// this actually kicks it
local velocity = Instance.new("BodyVelocity")
velocity.Parent = target
velocity.MaxForce = Vector3.new(1, 1, 1) * math.huge
velocity.Velocity = dir.Unit * 60 + Vector3.new(0,80,0)
--// particle
local attach = Instance.new("Attachment")
attach.Parent = target
local particle = game.ReplicatedStorage.FX.Kick
local clone = particle:Clone()
clone.Parent = attach
clone:Emit(1)
debris:AddItem(velocity, 0.2)
target.Anchored = false
print('KICKED:', target)
end
local legs = char["Left Leg"] or char["Right Leg"]
legs.Touched:connect(function(hit)
if hit == KICK and kicked == false then
local customSound = KICK:FindFirstChildWhichIsA("Sound")
if customSound and customSound.Name == "Kick" then
customSound:Play()
end
kick(hit)
kicked = true
despawnPart(hit)
end
end)
end