I’ve been trying to make a function where a part starts spinning and overtime it gets faster and faster. If a local player dies then that part stops and starts spinning again at a slow pace and then gets faster overtime. Here I have a function in a local script.
local Beam = game:GetService("ReplicatedStorage"):WaitForChild("Beam"):Clone()
Beam.Parent = workspace.CurrentCamera
local function Move()
local speed = 0.001
local something = true
Player.Character.Humanoid.Died:Connect(function()
wait(2)
something = false
end)
while something do
task.wait()
Beam.CFrame = Beam.CFrame * CFrame.fromEulerAnglesXYZ(speed, 0, 0)
speed = math.clamp(speed + (0.001 / 90), 0.001, 30)
end
Move()
end
The problem is the function works the first time but not anytime after that.
You could see that when the player resets the first time the beam stops and starts spinning slowly and then speeds up. But if the player resets a second time after that then that same thing wont happen. I was wondering how too fix this, thanks.
local Beam = workspace.CurrentCamera:FindFirstChild("Beam")
if Beam then Beam:Destroy() end
Beam = game:GetService("ReplicatedStorage"):WaitForChild("Beam"):Clone()
Beam.Parent = workspace.CurrentCamera
local speed = 0.001
while script.Parent and script.Parent.Parent do
task.wait()
Beam.CFrame = Beam.CFrame * CFrame.fromEulerAnglesXYZ(speed, 0, 0)
speed = math.clamp(speed + (0.001 / 90), 0.001, 30)
end
Thank you, but I am trying to make it where when the local player dies the beam resets and starts spinning slowly and then eventually gets faster. And this repeats over and over again as soon as the player dies. If what I’m explaining is too complicated please ask me to try and reexplain.
I’m not sure but I did download the video and watched it through. What you did in the video was exactly what I wanted to happen. For some reason what is happening for you isn’t happening for me. When I test play the game the beam isn’t being cloned.
Here is what im using -
local Beam = workspace.CurrentCamera:FindFirstChild("Beam")
if Beam then Beam:Destroy() end
Beam = game:GetService("ReplicatedStorage"):WaitForChild("Beam"):Clone()
Beam.Parent = workspace.CurrentCamera
local speed = 0.001
while script.Parent and script.Parent.Parent do
task.wait()
Beam.CFrame = Beam.CFrame * CFrame.fromEulerAnglesXYZ(speed, 0, 0)
speed = math.clamp(speed + (0.001 / 90), 0.001, 30)
end
Thanks so much, I was really struggling with this. One last question if possible. Is there anyway I can trigger this with a RemoteEvent?
For example, would something like this work?
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage.Remotes:WaitForChild("Spinner")
local Beam = workspace.CurrentCamera:FindFirstChild("Beam")
if Beam then Beam:Destroy() end
Beam = game:GetService("ReplicatedStorage"):WaitForChild("Beam"):Clone()
Beam.Parent = workspace.CurrentCamera
local function spin()
local speed = 0.001
while script.Parent and script.Parent.Parent do
task.wait()
Beam.CFrame = Beam.CFrame * CFrame.fromEulerAnglesXYZ(speed, 0, 0)
speed = math.clamp(speed + (0.001 / 90), 0.001, 30)
end
end
remoteEvent.OnClientEvent:Connect(spin)
Maybe something like this if you need more control, such as stopping and starting
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage.Remotes:WaitForChild("Spinner")
local Beam = workspace.CurrentCamera:FindFirstChild("Beam")
if Beam then Beam:Destroy() end
Beam = ReplicatedStorage:WaitForChild("Beam"):Clone()
Beam.Parent = workspace.CurrentCamera
local defaultCFrame = Beam.CFrame
local speed = 0.001
local stopped = true
function DoSpin()
while script.Parent and script.Parent.Parent do
task.wait()
if not stopped then
Beam.CFrame = Beam.CFrame * CFrame.fromEulerAnglesXYZ(speed, 0, 0)
speed = math.clamp(speed + (0.001 / 90), 0.001, 30)
end
end
end
remoteEvent.OnClientEvent:Connect(function(message)
message = message or "Start"
if message == "Start" then
stopped = false
else
stopped = true
end
end)
DoSpin()
Hm, this didn’t seem to work. This is still supposed to be a local script in StarterCharacterScripts right? What happens is when the function is called and the player dies the beam just stops. It stops and it doesn’t start rotating again.
So if its spinning and you reset or die, did you want it to remain in the last state it was in?
Did you want it to maintain the same speed, or reset the speed?
Not sure exactly what you wanted it to do, but was just suggesting a way you could turn it on and off.
In the code below, we set an attribute on the Beam to state if it is Stopped or not.
So if you reset, it will remember if it is Stopped, but the speed will reset and start out slow again, it will also set its starting position to the default.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage.Remotes:WaitForChild("Spinner")
local Beam = workspace.CurrentCamera:FindFirstChild("Beam")
if not Beam then
Beam = ReplicatedStorage:WaitForChild("Beam"):Clone()
Beam.Parent = workspace.CurrentCamera
Beam:SetAttribute("Stopped",true)
end
Beam.CFrame = ReplicatedStorage:WaitForChild("Beam").CFrame
local speed = 0.001
function DoSpin()
while script.Parent and script.Parent.Parent do
task.wait()
if not Beam:GetAttribute("Stopped") then
Beam.CFrame = Beam.CFrame * CFrame.fromEulerAnglesXYZ(speed, 0, 0)
speed = math.clamp(speed + (0.001 / 90), 0.001, 30)
end
end
end
remoteEvent.OnClientEvent:Connect(function(message)
message = message or "Start"
if message == "Start" then
Beam:SetAttribute("Stopped",false)
else
Beam:SetAttribute("Stopped",true)
end
end)
DoSpin()