Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

(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

0
What is the error? danglt 185 — 5y

1 answer

Log in to vote
0
Answered by
Lazarix9 245 Moderation Voter
5 years ago
Edited 5 years ago

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.

0
It does not work i think its cuz of my script RoomScripter 3 — 5y
0
Nvm ive fixed it its cuz the localscript was in StarterPlayerScripts And i Moved it To StarterCharacterScript RoomScripter 3 — 5y
0
This might be asking too much but is it possible to make a script that will disable the camera shake script? RoomScripter 3 — 5y
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 Lazarix9 245 — 5y
1
Its fine! And Thanks RoomScripter 3 — 5y
Ad

Answer this question