i moved the script to StarterGui and it worked however when I reset my character to test it wouldn’t shake the screen again after the character respawned
That error seems to be from a different script, maybe it’s from the same script, though that would mean you haven’t given me all of the code in the script making it practically impossible for me to find why that error appears.
As for the difference, StarterGui is for Gui’s, you’re gonna make it unnecessarily messy by placing random LocalScripts in there rather than StarterPlayerScript.
local CenterGem = workspace:WaitForChild("CenterGem")
local RNGDisplayUI = CenterGem:WaitForChild("RNGDisplayUI")
local OrbData = require(game:GetService("ServerStorage"):WaitForChild("OrbData"))
local function ChooseRandomOrb()
local totalWeight = 0
for OrbType, Data in pairs(OrbData) do
totalWeight = totalWeight + Data.SpawnOdds
end
local randomValue = Random.new():NextNumber(0,totalWeight)
local cumulativeWeight = 0
for OrbType, Data in pairs(OrbData) do
cumulativeWeight = cumulativeWeight + Data.SpawnOdds
if randomValue <= cumulativeWeight then
return OrbType -- return the orb name
end
end
end
local MultiplierOrbs = game:GetService("ReplicatedStorage"):WaitForChild("MultiplierOrbs")
local OrbStorage = workspace:WaitForChild("OrbStorage")
local MaxOrbs = 15
local OrbSpawnPositions = workspace:WaitForChild("OrbSpawnPositions")
local function ChooseOrbSpawnPos()
local xMin = math.min(OrbSpawnPositions.X1.Position.X,OrbSpawnPositions.X2.Position.X)
local xMax = math.max(OrbSpawnPositions.X1.Position.X,OrbSpawnPositions.X2.Position.X)
local zMin = math.min(OrbSpawnPositions.Z1.Position.Z,OrbSpawnPositions.Z2.Position.Z)
local zMax = math.max(OrbSpawnPositions.Z1.Position.Z,OrbSpawnPositions.Z2.Position.Z)
return CFrame.new(math.random(xMin,xMax),1.875,math.random(zMin,zMax))
end
local function OrbSpawner()
while true do
local OrbsToSpawn = MaxOrbs - #OrbStorage:GetChildren()
if OrbsToSpawn > 0 then
for num = 1,OrbsToSpawn,1 do
local ChosenOrb = ChooseRandomOrb()
local ClonedOrb = MultiplierOrbs:FindFirstChild(ChosenOrb):Clone()
ClonedOrb.Parent = OrbStorage
ClonedOrb.CFrame = ChooseOrbSpawnPos()
end
end
task.wait(12)
end
end
spawn(OrbSpawner)
local ServerMulti = game:GetService("ReplicatedStorage"):WaitForChild("ServerMulti")
local RequiredRNG = 0.000001
RNGDisplayUI.Holder.TargetRNG.Text = "🎯 " .. tostring(math.round(RequiredRNG * ServerMulti.Value * 1000000) / 1000000)
ServerMulti:GetPropertyChangedSignal("Value"):Connect(function()
RNGDisplayUI.Holder.TargetRNG.Text = "🎯 " .. tostring(math.round(RequiredRNG * ServerMulti.Value * 1000000) / 1000000)
end)
local GemConfig = {
AnimDuration = 12;
DefaultSize = Vector3.new(1.5,1.5,1.5);
FinalSize = Vector3.new(100,100,100);
DefaultPos = Vector3.new(0,4.5,0);
FinalPos = Vector3.new(0,100,0);
}
local RemoteEvents = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvents")
local ShakeScreen = RemoteEvents:WaitForChild("ShakeScreen")
local AuraScreenEffect = RemoteEvents:WaitForChild("AuraScreenEffect")
local Auras = {
"Ruby";
"Fire Opal";
"Citrine";
"Emerald";
"Sapphire";
"Rubellite";
"Amethyst";
}
while true do
local RNG = math.round(Random.new():NextNumber(0,100) * 1000000) / 1000000
local LatestRolledNum = tostring(math.round(RNG * 1000000) / 1000000)
for i = 1,string.len(LatestRolledNum),1 do
RNGDisplayUI.Holder.CurrentRoll.Text = "CURRENT: " .. string.sub(LatestRolledNum,1,i)
RNGDisplayUI.Holder.CurrentRoll.DropShadow.Text = "CURRENT: " .. string.sub(LatestRolledNum,1,i)
task.wait(0.1)
end
if RNG <= RequiredRNG * ServerMulti.Value then
ServerMulti.Value = 1
local ChosenAuraToAward = Auras[math.random(1,#Auras)]
print(ChosenAuraToAward)
local TS = game:GetService("TweenService")
TS:Create(CenterGem.FloatingGem,TweenInfo.new(GemConfig.AnimDuration,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut),{Size = GemConfig.FinalSize}):Play()
TS:Create(CenterGem.FloatingGem,TweenInfo.new(GemConfig.AnimDuration,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut),{Position = GemConfig.FinalPos}):Play()
ShakeScreen:FireAllClients(GemConfig.AnimDuration + 3)
task.wait(GemConfig.AnimDuration)
AuraScreenEffect:FireAllClients(ChosenAuraToAward)
task.wait(3)
CenterGem.FloatingGem.Size = GemConfig.DefaultSize
CenterGem.FloatingGem.Position = GemConfig.DefaultPos
end
task.wait(1)
end
Okay, I’m honestly at a lost, I have no clue where the error starts, or if it even has a start. So the cut short, just disable the reset button. The game seems to be an RNG game, so you’re not suppose to even be dying, so just disable the reset button. AGgawgha
local plr = game.Players.LocalPlayer
local ShakeScreen = game:GetService("ReplicatedStorage").RemoteEvents.ShakeScreen
ShakeScreen.OnClientEvent:Connect(function(Duration)
print("Starting screen shake.")
local StartTime = tick()
repeat
local Char = plr.Character or plr.CharacterAdded:Wait()
local Hum = Char:WaitForChild("Humanoid")
task.wait()
local EndTime = tick()
local xOffset = math.random(-100,100) / 850
local yOffset = math.random(-100,100) / 850
local zOffset = math.random(-100,100) / 850
if Hum.Health > 0 then
Hum.CameraOffset = Vector3.new(xOffset,yOffset,zOffset)
end
until EndTime - StartTime >= Duration
Hum.CameraOffset = Vector3.new(0,0,0)
end)
Bc the character is removed and then added back I had to put it back in the repeat loop
local Char = plr.Character or plr.CharacterAdded:Wait()
local Hum = Char:WaitForChild("Humanoid")
You could have just moved this script to the ‘StarterPlayerScripts’ container so that it isn’t destroyed each time the player’s character model is destroyed.
local players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
local player = players.LocalPlayer
local remoteEvent = replicatedStorage:WaitForChild("RemoteEvent")
local function onClientEvent(v) --duration
local t = 0
while true do
t += task.wait()
local character = player.Character --get character
if not character then continue end --if no character wait until new character
local humanoid = character:FindFirstChild("Humanoid") --get humanoid
if (not humanoid) or humanoid.Health == 0 then continue end --if no humanoid or humanoid's health is 0 wait until new humanoid
humanoid.CameraOffset = Vector3.new(math.random(-100, 100) / 850, math.random(-100, 100) / 850, math.random(-100, 100) / 850)
if t > v then break end
end
humanoid.CameraOffset = Vector3.new(0, 0, 0) --reset camera
end
remoteEvent.OnClientEvent:Connect(onClientEvent)