I have been cracking my head at this for like 3 hours. So, i am making a pvp-like game and i want to make it so whenever this “Mic” part touches anything it stops its flight early and falls down but if its a player then it also deals 10 damage, but it has been a nightmare to code, the only things it seems to interact with is: the baseplate, rigs (with its humanoidrootpart unanchored and only if it is unanchored for some reason) and thats it. While it SHOULD interact with things such as props and well, rigs with humanoidrootparts anchored. Heres a list of all things i tried to do:
-
I tried checking if the parts had cantouch off, they did not.
-
I tried using prints to find out where it goes wrong for some reason the .Touched function doesnt even want to trigger itself if it is not colliding with a player or a baseplate
Here’s the video of it in action:
The ServerScriptService code:
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local atkDb = false
local atkReady = true
local Event = game.ReplicatedStorage.TossMic -- Path to Remote Event
Event.OnServerEvent:Connect(function(Player)
if atkReady == true then
atkReady = false
local character = Player.Character
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local block = ReplicatedStorage:WaitForChild("Mic"):Clone()
block.Parent = workspace
block:PivotTo(humanoidRootPart.CFrame * CFrame.new(0,0,-3))
block.Orientation = humanoidRootPart.Orientation
block.Throw:Play()
local moveDirection = humanoidRootPart.CFrame.LookVector
local moveSpeed = 30
local spinSpeed = -10
block.Touched:Connect(function(hit)
print("Touched!")
if hit.Parent:FindFirstChild("Humanoid") then
local humanoid = hit.Parent.Humanoid
if humanoid.Parent.Name ~= Player.Name and atkDb == false then
atkDb = true
block.Hit:Play()
hit.Parent.Humanoid:TakeDamage(10)
moveSpeed = 0
spinSpeed = 0
block.CanTouch = false
block.CanQuery = false
block.CanCollide = true
block.Anchored = false
end
else
print("Touched a non player!")
moveSpeed = 0
block.CanCollide = true
block.Anchored = false
end
end)
RunService.Heartbeat:Connect(function(dt)
block.CFrame = (block.CFrame + moveDirection * moveSpeed * dt) * CFrame.fromEulerAngles(math.rad(spinSpeed), 0, 0)
end)
task.wait(1.2)
block.CanCollide = true
block.Anchored = false
wait(0.4)
block:Destroy()
atkDb = false
task.wait(1)
atkReady = true
end
end)
am i missing some obvious mistake?