So I’m trying to make a touch function that turns off the disabled Shake, and when I tested it, the script worked by turning Disabled to false, but the Screen Shake didn’t work. Also, this is my first time making a post in this category, so tell me if I need to include or exclude stuff.
The Screen Shake does work when it is manually enabled in Studio, but I’m not sure what’s causing this in the Test Client.
local Shake = game.StarterPlayer.StarterCharacterScripts.CameraShakeScript
function onTouched(hit)
Shake.Disabled = false
end
script.Parent.Touched:connect(onTouched)
Script that activates the Shake that goes into a part.
math.randomseed(tick())
local runService = game:GetService("RunService")
local char = script.Parent
local hum = char:WaitForChild("Humanoid")
local nextFire = 0
local shakeRate = 0.05
local shakeMin = 0
local shakeMax = 500
runService.RenderStepped:Connect(function()
if elapsedTime() > nextFire then
nextFire = elapsedTime() + shakeRate
hum.CameraOffset = Vector3.new(math.random(shakeMin, shakeMax)/1000, math.random(shakeMin, shakeMax)/1000, math.random(shakeMin, shakeMax)/1000)
end
end)
The Shake Script that goes in StarterCharacterScripts
Plus, when I tested this in an empty Baseplate, the smae results happened. Disabling my Plugins do nothing. Please tell me if there is a problem
local Shake = game.StarterPlayer.StarterCharacterScripts.CameraShakeScript
u need to delete that and on the function put:
function onTouched(hit)
local Shake = hit.Parent:FindFirstChild('CameraShakeScript')
if Shake then
Shake.Disabled = false
end
end
script.Parent.Touched:Connect(function(hit)
OnTouched(hit)
end)
You are writing this in your script that controls the camera shake:
if elapsedTime() > nextFire then
This will cause an error for one of two reasons,
A legitimate error because you have not defined “elapsedTime()”, though you may have defined it previously in the script, if you did please show that section of the script which was left out.
You have “nextFire” set by default to 0, meaning that “if elapsedTime() > nextFire then” will always be true.
Not sure how helpful any of these, though the 1st point will most likely be the most helpful.
if u mean by “The same thing happens to the game.” it make the same thing. ur wrong becouse u activate it for new players, my script activates for the player that hit the part
In my response that was seemingly ignored, I explained that the error will be coming from the camerashake script itself, evidently seeing-as the touched script is working that’s not the issue. Once again I will explain that this line of code:
if elapsedTime() > nextFire then
Is most likely causing you errors. You have not defined “elapsedTime()” anywhere in your script, which means you are attempting to compare a nil to a number value. Once you define the “elapsedTime()” variable somewhere in your script it should be fine. I’m also not sure why you are calling “elapsedTime” with the parentheses, seeing as it should be a static variable as opposed to a function.
What do you mean?
That literally affects nothing …
You could either connect an event to a predefined function or use an anonymous function directly performing an action on an Event, I don’t see any difference.
@70Night Are you sure the script detecting the .Touched event is a server script?
A local script won’t work in that case.
local player = players.LocalPlayer
script.Parent.Touched:Connect(function(hit)
local character = hit:FindFirstAncestorOfClass("Model")
local CameraShakeScript = character:FindFirstChild("CameraShakeScript")
CameraShakeScript.Disabled = false
end)
They’re referencing StarterPlayer so they’re just editing the starter script. The children of StarterCharacterScripts are cloned into the character on spawn.