What solutions have you tried so far? Did you look for solutions on the Developer Hub?
i tried deleting, destroying, disabling the script but its still running
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
this is the script that sets the position of the camera to for the main menu
local cam = workspace.CurrentCamera
local Players = game:GetService("Players")
local player = Players.LocalPlayer
cam.CameraType = "Scriptable"
local pos = Vector3.new(-200, 50, -50)
local lookAt = Vector3.new(0,0,0)
local cameraCFrame = CFrame.new(pos, lookAt)
workspace.CurrentCamera.CFrame = cameraCFrame
player.CameraMinZoomDistance = 5
player.CameraMaxZoomDistance = 10
and heres the script that moves the camera back to the character
local button = script.Parent
local function onButtonActivated()
button.Parent.Parent.Visible = false
game.Workspace.CurrentCamera.CameraType = "Custom"
game.StarterPlayer.StarterCharacterScripts.cameraLocalScript:Destroy()
game.Lighting.menuDepth.Enabled = false
end
button.Activated:Connect(onButtonActivated)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
“StarterPlayerScripts” is where you put scripts that affect the entire player’s game experience, player management, or global game mechanics.
“StarterPlayerCharacter,” on the other hand, is where you customize the initial appearance and properties of the player’s in-game character, including their model, animations, and initial state.
It’s about controlling the player’s avatar, while “StarterPlayerScripts” handles overall game behavior and interactions."
The code located in StarterPlayerCharacter is executed at the same time as the “CharacterAdded” event since the content of StarterPlayerCharacter is cloned in the character of the player.
This should explain why the code is executed every time.
You could put a value that is locally switched upon the player first joining the game. Assuming the script is a LocalScript and you only want it to run when the player first joins.
if workspace:FindFirstChild("ScriptAlreadyRun")== nil then
local val = Instance.new("BoolValue")
val.Parent = workspace
val.Name = "ScriptAlreadyRun"
end
if workspace:FindFirstChild("ScriptAlreadyRun").Value ~= true then
workspace:FindFirstChild("ScriptAlreadyRun").Value = true
--your code here--
end