Script Working But Not Reacting

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

3 Likes

first dont use connect,use Connect()
and dont use

script.Parent.Touched:connect(onTouched)

use

script.Parent.Touched:Connect(function(hit)
OnTouched(hit)
end)

Still results in the same thing, the script works and effects the disabled toggle, but there is no effect.

and u can’t use

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)


1 Like

The same thing happens to the game.

1 Like

it still dont work? please say if it gets any error

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,

  1. 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.
  2. 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

I’m sorry I’m having a hard to comprehend what your saying, I’m horrible at scripting.

im horrible at building but i try and i dont stop, same at scripting, hope u can repair ur scripts but im sure what i say should work

(cc @pro_developer213)

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.

I have already defined elaspedTime() in the script, I’ve left it out of the post because there was some important stuff I do not wish to share.

You need to check if the thing that touches the part is actually a player, then add debounce and see if that works

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.

Yes it is a Server script, I have changed it’s form many times to see if there is a diffrence.

Try changing the format to :

local player = players.LocalPlayer

 
    script.Parent.Touched:Connect(function(hit)
         local character = hit:FindFirstAncestorOfClass("Model")
   local CameraShakeScript = character:FindFirstChild("CameraShakeScript")

    CameraShakeScript.Disabled = false
   
   end)

??? You’re asserting the wrong things here.

Why would OP need to define elapsedTime? elapsedTime is a Roblox global assigned to a function. The problem is their own code wrongly referencing and implementing the shake.

They’re referencing StarterPlayer so they’re just editing the starter script. The children of StarterCharacterScripts are cloned into the character on spawn.

In that case then my function would be useless, let me try to see if that’s causing it.

Edit: No that still does nothing.

ive arleady said that, but thanks to say it more correctly!

That breaks it even more, not only is there no affect, but it doesn’t even turn disabling to true (Or maybe I set it up wrong).

PS: StartCharacterScripts are in StarterPlayer