ok, this is a wild guess, but maybe the client owns the part instead of the server. in the for loop, make sure the part has its network ownership set to nil to make it server sided
i.e:
local char = script.Parent -- this is fine
local hum = char:FindFirstChild("Humanoid")
local parts = workspace:GetChildren() -- or wherever your killparts are
local db = false
for _, part in pairs(parts) do
if part.Name == "damagePart" or part.Name == "killPart" then
part:SetNetworkOwner(nil)
end
part.Touched:Connect(function(hit)
if hit.Parent ~= char then return nil end
if part.Name == "damagePart" then
if db == true then return nil end
db = true
hum.Health -= 5
wait(1)
db = false
elseif part.Name == "killPart" then
hum.Health = 0
end
end)
end
local runService = game:GetService("RunService")
local damageRange = 5 -- Distance within which damage is applied
local debounceTime = 1 -- Cooldown time in seconds
local debounces = {} -- Table to track debounces for each player
local humanoid = script.Parent:FindFirstChild("Humanoid")
-- Ensure Humanoid exists
if not humanoid then
warn("Humanoid not found!")
return
end
-- Table to store damaging parts in the workspace
local damagingParts = {}
for _, part in pairs(workspace:GetChildren()) do
if part.Name == "damagePart" or part.Name == "killPart" then
table.insert(damagingParts, part)
end
end
-- Coroutine function for applying damage
local function applyDamage(damage)
-- Debounce check
if not debounces[humanoid] then
debounces[humanoid] = true
humanoid.Health -= damage
coroutine.wrap(function()
wait(debounceTime) -- Cooldown period
debounces[humanoid] = false -- Reset debounce after cooldown
end)()
end
end
-- Function to track player part positions
local function trackPlayer()
runService.Heartbeat:Connect(function()
if humanoid.Health > 0 then
for _, bodyPart in pairs(script.Parent:GetChildren()) do
if bodyPart:IsA("BasePart") then
for _, damagePart in pairs(damagingParts) do
local distance = (damagePart.Position - bodyPart.Position).Magnitude
-- If the player is within range of a damagePart or killPart
if distance <= damageRange then
if damagePart.Name == "damagePart" then
applyDamage(5) -- Damage amount
elseif damagePart.Name == "killPart" then
print("DEBUG: KILL PART TOUCHED")
applyDamage(math.huge) -- Instant kill
end
end
end
end
end
end
end)
end
-- Start tracking the player's proximity to damaging parts
coroutine.wrap(trackPlayer)()
It would be good to introduce good programming habits.
local SpinPart = [path]
local SpinSpeed = 5 -- How much to increment per 0.1 seconds
SpinSpeed = math.rad(SpinSpeed) -- Converts to radians (X / 180)
while true do
wait(0.1)
SpinPart.CFrame *= CFrame.fromEulerAngles(0, SpinSpeed, 0)
end
Unfortunately I do not have access to Studio at the moment. Can you provide the script text for the spinning brick if applicable?
Unfortunately that’s how it goes with technology. As time goes on it gets more difficult to maintain older features. Instead of opting to go back and re-write how they work in the modern engine and potentially breaking the behavior that older games / gears relied on, they mark them as deprecated meaning that they’re out of support and will not be updated. If they break down the line, that’s unfortunately the reality for them.
Getting back on topic, the OP could use the BodyGyro bodymover. Since bodymovers update with the physics engine, it’s perfect to use in cases where it involves the player’s character.
BodyGyro.MaxTorque = Vector3.new(0, 9999, 0) -- Only applies force to the Y axis
BodyGyro.D = 1111
BodyGyro.P = 9999
while true do
BodyGyro.CFrame *= math.rad(0, math.pi / 4, 0) -- Rotates 45 degrees every 0.1 seconds
wait(0.1)
end
The only downside is that the part cannot be anchored with legacy bodymovers, otherwise they will not work.
local cos = game:GetService("CollectionService")
local run = game:GetService("RunService")
local dmgBrickNme = "damage_brick"
local dmgNme = "dmg"
local cdNme = "cooldwn"
local speed = 3
for _, brick in cos:GetTagged(dmgBrickNme) do
if brick:IsA("BasePart") then
local connection = nil
local deb = false
local damage = brick:GetAttribute(dmgNme) or 20
local cooldown = brick:GetAttribute(cdNme) or .5
local function spin()
run.Stepped:Connect(function(...)
brick.CFrame *= CFrame.Angles(0, math.rad(speed), 0)
end)
end
spin()
local function touched(hit:Part)
local p = hit.Parent:FindFirstChildWhichIsA("Humanoid")
if p and p.Health > 0 and not deb then
deb = true
p:TakeDamage(damage)
task.wait(cooldown)
deb = false
end
end
connection = brick.Touched:Connect(touched)
end
end
Check if the basepart that touched is part of a player. This also happens to me for some reason and I don’t know why, but doing that fixes the problem atleast for me.
Physics are handled on the server, so whilst .Touched ran without you actually touching the part on the client, the server detects that you have in fact touched it; from the perspective of the server. To fix this, you are going to need to render the spinning part on the client and set the spinning part’s network owner to that client. Of course, you will need to send a call to the server when the client touches the spinning part.