What i want to achieve is disabling a local script through a normal script and reEnabling the local script, how would i do that?
i tried doing this:
game.StarterPlayer.StarterCharacterScripts.CamShakerCar.enabled = true --enabling the local script
game.StarterPlayer.StarterCharacterScripts.CamShakerCar.enabled = false --disabling the local script
And ive also tried RemoteEvents but i couldn’t get it to work.
i have also read multiple devforum posts but they did not fix my problem.
Can anyone help me?
i’d be very happy to have a solution.
I think it’s because you used “enabled” in a wrong form? Isn’t it? I think i may be wrong, but here it is:
game.StarterPlayer.StarterCharacterScripts.CamShakerCar.Enabled = true --enabling the local script
game.StarterPlayer.StarterCharacterScripts.CamShakerCar.Enabled = false --disabling the local script
You’re directly disabling the script from the StarterCharacterScript, which will not apply for those who have been already copied to active characters.
The script in StarterCharacterScripts is basically a template that will be cloned into every character. Meaning disabling it or enabling will not apply for characters that already have the script.
Maybe try game.Players:WaitForChild(ThePlayersName).PlayerScripts.CamShakerCar.Enabled = false
Like someone else above me said, StarterPlayer just replicates all of the scripts to the player.
Because i have a ProximityPrompt in a part, and when i press it, it works as a car horn
local ProximityPrompt = script.Parent.ProximityPrompt
local CarHornSound = script.Parent.Horn
ProximityPrompt.PromptButtonHoldBegan:Connect(function()
CarHornSound:Play()
local Triggered = false
print("Player is holding the prompt") -- Holding the prompt so the car horn will play, hold duration is infinite
local abc = ProximityPrompt.PromptButtonHoldEnded:Once(function()
task.wait()
if Triggered then
CarHornSound:Stop() -- Ignore this
else
print("Player let go of prompt")
CarHornSound:Stop() --Player let go of prompt
end
end)
local abcd = ProximityPrompt.Triggered:Once(function()
Triggered = true
end)
end)
and heres the local script that should get activated if the prompt is being held
game:GetService("RunService").RenderStepped:Connect(function()
if game.Workspace.Car.Body:FindFirstChild("ProxPromptTest") then
local intensity = 25
local range = 55
local dist = game.Players.LocalPlayer:DistanceFromCharacter(game.Workspace.Car.Body:FindFirstChild("ProxPromptTest").Position)
local cam = workspace.Camera
local clamp = math.clamp(1 + (intensity - 0.1)*(1-(dist/range)), 0.1, intensity)
cam.CFrame *= CFrame.Angles(math.random(1 - clamp, clamp) / 500, math.random(1 - clamp, clamp) / 500, math.random(1 - clamp, clamp) / 500)
game:GetService('TweenService'):Create(game.Workspace.Camera,TweenInfo.new(0.2,Enum.EasingStyle.Quint,Enum.EasingDirection.Out,0,false,0),{CFrame = cam.CFrame*CFrame.Angles(0,0,math.rad(math.random(-clamp/2, clamp/2)))}):Play()
game.Players.LocalPlayer.Character.Humanoid.CameraOffset = Vector3.new(math.random(1 - clamp, clamp / 20), math.random(1 - clamp, clamp / 20), math.random(0 - clamp, clamp / 15)) / 55
else
print('where is it')
end
end)
Sounds pretty simple, but did you try using :WaitForChild()? If this code is running right when the game loads there’s a chance the script just hasn’t loaded yet.