Hello, I've been trying to work with buttons and figure out how they work, I'm a complete newcomer, so I'm trying something easy, which is simply to increase a players speed for a short amount of time by pressing a button. However, every attempt I do breaks something, or simply fails to work. I just haven't been able to figure out how to make the buttons affect the player. If anyone could give me assistance, I'd greatly appreciate it.
Local Script for ScreenGUI
-- ABILITY BUTTONS
local Ability1 = script.Parent.ScreenGui.Ability1
-- Ability 1
local Ability1 = script.Parent.ScreenGui.Ability1
Ability2.MouseButton1Click:Connect(function()
print('Lets pick up the pace!')
end)```
**Player Local Script**
-- Shift to Run
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local Speed1 = 30
local Speed2 = 15
humanoid.WalkSpeed = Speed1
-- Run Button
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if gameProcessedEvent then return end
if input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.LeftShift then
humanoid.WalkSpeed = Speed2
end
end)
UserInputService.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.LeftShift then
humanoid.WalkSpeed = Speed1
end
end)
Most of my code here is borrowed from other sources, and I've been trying to tinker with it to learn how it works, but I've gotten stuck on this.
** You are now Level 1! **