What do you want to achieve?
To disable or enable the script in the character model.
What is the issue?
Im not sure on how to path to the camerabobbing script through the character model. Both are local scripts. I need it to only affect the player that enables or disables it.
What solutions have you tried so far?
Searched the dev forum.
LocalPlayer refers to the Player instance, you need to do LocalPlayer.Character in order to get the character
also if you are making a game, please don’t when you’re just starting
don’t make the same mistake i did, learn on smaller things first, otherwise when you learn you’re gonna be in rewriting hell constantly
In both cases you have incorrectly addressed the path to the local player’s character (game.Players.LocalPlayer and game.Workspace.Character are not player characters), here’s how it should be done:
local plr = game.Players.LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()
local scriptt = character:WaitForChild("CameraBobbing")
Note that the CameraBobbing script will reset if the character respawns.
local plr = game.Players.LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()
local scriptt = character:WaitForChild("CameraBobbing")
local enabled = scriptt.Enabled
button.MouseButton1Click:Connect(function()
scriptt.Enabled = not scriptt.Enabled
enabled = scriptt.Enabled
end)
plr.CharacterAdded:Connect(function(char)
scriptt = char:WaitForChild("CameraBobbing") --otherwise the scriptt variable will be a script of parent nil because it was parented to a dead character
scriptt.Enabled = enabled
end)