Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Script that is meant to enabled a local script is not working?

(Sorry For bad English) So I have a camera shake script in my StarterCharacterScripts And I set it to disabled Reason is I don't want it to activate when the game starts only when the player touches a Part or so like a trigger so I made the following code for it:

game.Workspace.Shake.Touched:Connect(function(hit)
	local Char = hit.Parent
	Char.Shake.Disabled = false
end)

But the Problem is that when I step on the part The Code Does Run And The Shake Script inside the Character has Disabled set to false but the thing is that the script is not running I really want to fix this problem put it stresses me out when I try to think about it Can anyone help?

Thanks

1 comment

0

What is the error?

1 answer

✓ Accepted answer

I don't think you can do that. I tried using RemoteEvents and it worked for me so I'm gonna tell you what to do. First, put a RemoteEvent in ReplicatedStorage, name it something like ShakeCamEvent or something. Then get a script and put it inside the part that you want to touch. Write this in it:

--Script

--Variables
local Shake = script.Parent
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local ShakeCamEvent = ReplicatedStorage:WaitForChild('ShakeCamEvent')
--Code
Shake.Touched:Connect(function(hit) --When part is touched

	local player = game:GetService('Players'):GetPlayerFromCharacter(hit.Parent) --Getting player object in order to fire the client
	
	
	if player then -- if we get a player object
		
		ShakeCamEvent:FireClient(player) --fire client
		
	end
	
end)

Now that we have that, go into StarterPlayer > StarterCharacterScripts, and add a localscript

--LocalScript

--Variables
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local CamShakeEvent = ReplicatedStorage:WaitForChild('ShakeCamEvent')
--Functions
local function onCamShake()
	
	--your camera shake code, sorry i can't write it, i dont really know how :|

end

--Code
CamShakeEvent.OnClientEvent:Connect(onCamShake)

That's it. I'm sorry if this does not work.

5 comments

0

It does not work i think its cuz of my script

0

Nvm ive fixed it its cuz the localscript was in StarterPlayerScripts And i Moved it To StarterCharacterScript

0

This might be asking too much but is it possible to make a script that will disable the camera shake script?

0

It is, first state your condition and say 'game.StarterPlayer.StarterCharacterScripts.LocalScript.Disabled = true' inside a script, and sorry for the StarterPlayer thing, I made a mistake there

1

Its fine! And Thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.