Crouch key to button

Im a newbie and its pretty hard for me to script things like this bc i almost do not script anything about buttons so could you make it for me? if you dont have time i do understand

This is a grate opportunity for you to improve you scripting ability

if you try your best to script it yourself and share your code here ill be here waiting to help you and ill tell you what to do to get your script working

1 Like

Ok, ill try bro :slight_smile: thanks you

(30 thingie)

And what were the errors precisely? It should work.

1 Like

I did this:

local UserInputService = game:GetService("UserInputService")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local crawlAnim = humanoid:LoadAnimation(script:WaitForChild("CrawlAnim"))
local isCrawling = false

humanoid.Running:Connect(function(speed)
	if speed > 0 then
		crawlAnim:AdjustSpeed(1)
	else
		crawlAnim:AdjustSpeed(0)
	end
end)

script.Parent.MouseButton1Click:Connect(function()
		if not isCrawling then
			isCrawling = true
			crawlAnim:Play()
			crawlAnim:AdjustSpeed(0)
			humanoid.WalkSpeed = 12
			humanoid.JumpPower = 0
		else
			crawlAnim:Stop()
			humanoid.WalkSpeed = 16
			humanoid.JumpPower = 50
			isCrawling = false
		end
	end
end)

and it said: Syntax Error: (29,1) Expected ‘)’ (to close ‘(’ at line 15), got ‘end’
also im pretty sure mousebutton1click will not work in mobile (the button its made for mobile)
i would really appreciate if you solve it for me altough even when its fixed i will try to modify 5uphi’s script to improve my scripting ability, thanks :slight_smile:

Ok so i fixed the syntax error it was pretty dumb but i still think mousebutton1click will not work with mobile, i tried script.Parent.Activated:Connect(function() and it didnt work theres no errors or animations

Ok so that’s good

The error is happing because you have 1 to many ends at the bottom remove one of the ends

Also instead of using mousebutton1click

Use Activated

https://developer.roblox.com/en-us/api-reference/event/GuiButton/Activated

1 Like

Oh we posted at the same time, thats what i did idk if im not using activated correctly

Heres the script

local UserInputService = game:GetService("UserInputService")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local crawlAnim = humanoid:LoadAnimation(script:WaitForChild("CrawlAnim"))
local isCrawling = false

humanoid.Running:Connect(function(speed)
	if speed > 0 then
		crawlAnim:AdjustSpeed(1)
	else
		crawlAnim:AdjustSpeed(0)
	end
end)

script.Parent.Activated:Connect(function()
	if not isCrawling then
		isCrawling = true
		crawlAnim:Play()
		crawlAnim:AdjustSpeed(0)
		humanoid.WalkSpeed = 12
		humanoid.JumpPower = 0
	else
		crawlAnim:Stop()
		humanoid.WalkSpeed = 16
		humanoid.JumpPower = 50
		isCrawling = false
	end

end)

Activated should work I use it all the time

It was another dumb error i tought thats why it wanst working i added the script in an incorrect button but its still not working

If you print(isCrawling) inside the function when you press the button does it print anything?

Nope it doesnt print anything
(30 thingie)

And it’s a localscript inside the correct button

Yes, ill send you the entire screengui:
MobileCrouch.rbxm (6.1 KB)

I’m currently on my mobile phone so I can’t open that file

Do you have a CrawlAnim inside the script?

Yes, heres the image and the animation does have an id from an animation i made
image

print("LocalScript started")

script.Parent.Activated:Connect(function()
    print("Activated")
end)

If you only have this in a localscript does this work?

Yes, it does work
(30 thingie…)

Ok now slowly add all your code in and try to find when it stops working

1 Like