I’m a new scripter, so I have no clue how to do this. But I’ve got this crouching script in StarterGUI, but I’ve also got this sprinting script in StarterCharacterScripts. So I can crouch and run at the same time, or vice versa. I usually prevent that with something like script.Parent.CrouchScript.Disabled= True
, but since they are in different areas of Studio, I don’t know how to do that.
If you want to disable scripts during runtime, you’ll have to access the player’s character, then locate the script you want to disable.
Everytime the character respawns, everything inside StarterCharacterScripts is cloned into the player’s character in workspace.
I don’t really know how to do that?
Maybe something like this? Character.Humanoid.RunAnimation.Disabled = true
You can’t get the script from the humanoid. Unless you put it under Humanoid.
i just figured it out i’m dumb lol
Here’s an example, using the PlayerAdded & CharacterAdded event Roblox offers:
local Players = game:GetService('Players')
local function PlayerAdded(Player)
local function CharacterAdded(Character)
local Script = Character:FindFirstChild('Script name')
if Script then
Script.Disabled = true -- If you want to disable it.
end
end
local Character = Player.Character
if Character then -- If the character exists, run the CharacterAdded function in parallel.
coroutine.resume(coroutine.create(function()
CharacterAdded(Character)
end))
end
Player.CharacterAdded:Connect(CharacterAdded) -- Wait for the character to be added, then run the CharacterAdded function.
end
local GetPlayers = Players:GetPlayers()
for i = 1, #GetPlayers do
coroutine.resume(coroutine.create(function()
PlayerAdded(GetPlayers[i])
-- Loop through existing players in parallel, that are in the server in case PlayerAdded did not fire in time.
-- Can be caused by delays, and WaitForChild (yields).
end))
end
Players.PlayerAdded:Connect(PlayerAdded) -- Listen for players to join, then run the PlayerAdded function for them.
1 Like