Activate local script

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.

1 Like

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

No i have tried that too, doesn’t work.

because Server Scripts can’t access StarterCharacterScripts. That’s a Local thing.

Try putting the local script in StarterGui (try to replace all positions of the script to that) and then put this:

game.StarterGui.CamShakerCar.Enabled = true --enabling the local script
game.StarterGui.CamShakerCar.Enabled = false --disabling the local script

And try to make so the local script’s source have anything to do with the character (i see you wanted it to do with the character)

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.

Oh he meant that?

02907490274902740297409274

Assuming so. There are no issues in the script, so assumed that.

i have now tried that but it does not work too.

Why would you need to disable and then enable the script?

Also, I believe the correct property is .Disabled

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.

I just checked and it is .Enabled

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)

You should be able to call :BindToRenderStep() when the prompt is triggered and then call :UnbindFromRenderStep() on .TriggerEnded.

How would that work with disabling and enabling the localscript

You shouldn’t need to disable the script.

But i want to make the screen shake when the prompt is being held (sorry if im a bit stupid)

Make the local script a function and use a remote events to call the bind and unbind renderstep methods from the main script.

I don’t really know how to do that im not really good or far in scripting

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.