Hello! This is my first post on the Devforum and I’m excited to be here! Now concerning my problem, I’m trying to make a Sonic engine and I have the damage script, but the rings don’t disappear. This is the script that is not running after it’s parent (or in this case, grandparent) changes:
I was going to ask if this was all in the same script. It gave me this error which I don’t understand: The current identity (2) cannot Source (lacking permission 1) - Client - Hurt:17
And also, I meant to write “rung” instead of “ring”.
Here is the updated one, which uses coroutine.create() instead of creating a new script.
-- Get the humanoid object
local humanoid = script.Parent.Parent:WaitForChild("Humanoid")
-- Define the function to generate rings
local function generateRings()
local ring = script.ring:Clone()
ring.Parent = script.Parent.Parent
ring.CFrame = humanoid.RootPart.CFrame
ring.Rotation = Vector3.new(math.random(1, 90), math.random(1, 90), math.random(1, 90))
ring.Anchored = false
ring.CanCollide = true
--Create Script for Ring
coroutine.resume(coroutine.create(function()
-- Wait for the parent and grandparent to load before running the script
repeat wait() until ring:IsA("Model") --// Change if Ring IsA MeshPart or something
-- Blink effect to simulate the ring disappearing
for i = 1, 4 do
ring.Transparency = 1
wait(0.1)
ring.Transparency = 0
wait(0.1)
end
ring:Destroy()
end))
end
-- Connect the Touched event to detect when the character is hit
humanoid.Touched:Connect(function(part)
if part.Name == "Hurt" or part.Name == "hurt" then
part.Name = "hirt"
local playerGui = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui")
if playerGui.rings.Value > 0 then
if playerGui.rings.Value <= 15 then
for i = 1, playerGui.rings.Value do
generateRings()
end
else
for i = 1, 15 do
generateRings()
end
end
end
playerGui.rings.Value = 0
end
end)
Why? Because the hurt script is a local script is StarterCharacterScripts and if I do it in a server script, it will remove the rings of every single player if one gets hurt.
You need to set the rings value to a special identifier like inside player folder or something. Anyways here is a better script handles most issues.
local Character:Model? = script.Parent
local Player = game:GetService("Players"):GetPlayerFromCharacter(Character)
local Humanoid:Humanoid? = Character:WaitForChild("Humanoid",25) or Character:FindFirstChildOfClass("Humanoid")
local function generateRings()
local ring = script.ring:Clone()
ring.Parent = workspace -- Parenting physics parts to character might cause some issues.
ring.CFrame = Character.PrimaryPart.CFrame
ring.Rotation = Vector3.new(math.random(1, 90), math.random(1, 90), math.random(1, 90))
ring.Anchored = false
ring.CanCollide = true
--Create Script for Ring
coroutine.wrap(function()
-- Wait for the parent and grandparent to load before running the script
repeat wait() until ring:IsA("Model") --// Change if Ring IsA MeshPart or something
-- Blink effect to simulate the ring disappearing
for i = 1, 4 do
ring.Transparency = 1
task.wait(0.1)
ring.Transparency = 0
wait(0.1)
end
ring:Destroy()
end)()
end
Humanoid.Touched:Connect(function(Part)
if tostring(Part):lower():match("hurt") then
Part.Name = "hirt" -- ?
local Rings:IntValue? = Player.Rings -- Rings!!
if Rings.Value > 0 then
if Rings.Value <= 15 then
for i = 1, Rings.Value do
generateRings()
end
else
for i = 1, 15 do
generateRings()
end
end
end
Rings.Value = 0
end
end)
It’s very exploitable in that case, a player might set its rings to inf or 0 to never lose them. heck, if they touch something that hurts they can briefly change them to 0 so they don’t lose it.
You can just use this.
local TextLabel:TextLabel? = script.Parent
local Player = game:GetService("Players").LocalPlayer
local Rings = Player.Rings
Rings.Changed:Connect(function(Value)
TextLabel.Text = tostring(Value)
end)
True, I might add an anti-cheat to check if the rings counter goes up more than 1. And if they get hurt when their rings are 0, they’re gonna get merked.