Alright another quick question. This is a follow-up to the Gamepass only gui that @Forummer found the solution for. I am trying to create a list of emotes that automatically cancel when you are trying to move.
I know my code is completely wrong but I tried at least:
local player = game.Players.LocalPlayer
local character = player.Character
repeat wait()
character = player.Character
until character
local hum = character:WaitForChild("Humanoid")
local emote = hum:LoadAnimation(script.Parent.Emote)
script.Parent.MouseButton1Click:connect(function()
if hum.MoveDirection == Vector3.new(0, 0, 0) then
emote:Play()
hum.WalkSpeed = 0
hum.JumpPower = 0
else
emote:Stop()
hum.WalkSpeed = 14
hum.JumpPower = 50
end
end)
Didn’t seem to fix it. Here`s what the code looks like:
local player = game.Players.LocalPlayer
local character = player.Character
repeat wait()
character = player.Character
until character
local hum = character:WaitForChild("Humanoid")
local emote = hum:LoadAnimation(script.Parent.Emote)
script.Parent.MouseButton1Click:connect(function()
if hum.MoveDirection == Vector3.new(0, 0, 0) then
emote:Play()
hum.WalkSpeed = 0
hum.JumpPower = 0
else
hum.Changed:Connect(function()
if hum.MoveDirection ~= Vector3.new(0,0,0) then
emote:Stop()
hum.WalkSpeed = 14
hum.JumpPower = 50
end
end)
end
end)
make the hum.Changed function outside of the entire script.Parent.MouseButton1Click function and it should work
local player = game.Players.LocalPlayer
local character = player.Character
repeat wait()
character = player.Character
until character
local hum = character:WaitForChild("Humanoid")
local emote = hum:LoadAnimation(script.Parent.Emote)
script.Parent.MouseButton1Click:connect(function()
if hum.MoveDirection == Vector3.new(0, 0, 0) then
emote:Play()
hum.WalkSpeed = 0
hum.JumpPower = 0
end
end)
hum.Changed:Connect(function()
if hum.MoveDirection ~= Vector3.new(0,0,0) then
emote:Stop()
hum.WalkSpeed = 14
hum.JumpPower = 50
end
end)
local players = game:GetService("Players")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local button = script.Parent
local emoteAnimation = button:WaitForChild("Emote")
local emoteTrack = humanoid:LoadAnimation(emoteAnimation)
repeat task.wait() until emoteTrack.Length > 0
button.MouseButton1Click:Connect(function()
if humanoid.MoveDirection.Magnitude == 0 then
emoteTrack:Play()
humanoid.WalkSpeed = 0
humanoid.JumpPower = 0
humanoid.JumpHeight = 0
end
end)
humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
if humanoid.MoveDirection.Magnitude > 0 then
emoteTrack:Stop()
humanoid.WalkSpeed = 16
humanoid.JumpPower = 50
humanoid.JumpHeight = 7.2
end
end)
A few issues, wait() has been superseded by task.wait(), “:connect()” is deprecated and has been replaced by “:Connect()”. You can use the magnitude of a player’s character’s move direction in order to determine if they are moving or not. The default walkspeed of a humanoid is 16 not 14, the “Humanoid.Changed” event fires whenever any of the humanoid’s properties change “:GetPropertyChangedSignal()” allows us to create an event signal object which only fires when a specified property changes. Finally, you should use the “.CharacterAdded” event instead of a “repeat wait loop” to detect when the player’s character has been added.