So I’ve been stuck for the last few days working on a prop damage system for a private project and it’s been a headache. I got it to work, problem is that it randomly destroys any object named “test” instead of the certain “test” that was Touched by the player.
server
SPS_Limit = 25
function onTouched(part)
--if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
local GotSpeed = math.floor(part.Velocity.Magnitude/2)
if part and part.Parent and GotSpeed > SPS_Limit then
local Player = game.Players:GetPlayerFromCharacter(part.Parent)
game.ReplicatedStorage.PartTouchedEvent:FireClient(Player)
script.Parent.HitSound:Play()
end
end
script.Parent.Touched:connect(onTouched)
localserver
local part = game.ReplicatedStorage.PartTouchedEvent
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
part.OnClientEvent:Connect(function(otherPart)
local remoteEvent = game:GetService("ReplicatedStorage").PartTouchedEvent
remoteEvent:FireServer(Player, part, otherPart)
for _, otherPart in pairs(game.Workspace:GetDescendants()) do
if otherPart.Name == "test" and otherPart.Touched then
otherPart.Anchored = false
wait(2)
otherPart:Destroy()
end
end
end)