hey! for context i’m making a 2d sprite in a 3d overworld and im trying to create walking animations based on the WSAD keys pressed. prints and stuff work good but for some reason when i press the key, the decal just disappears. no errors
local fw1 = "rbxassetid://14673295435"
local fw2 = "rbxassetid://14673304630"
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local dec = character:WaitForChild("HumanoidRootPart"):WaitForChild("BillboardGui"):WaitForChild("ImageLabel")
local aaa = game:GetService("UserInputService")
aaa.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.S then
dec.Image = fw1
task.wait(.5)
dec.Image = fw2
task.wait(.5)
end
end)
Decals are different from ImageIds. I converted your decals to ImageIds for you.
Code:
local fw1 = "http://www.roblox.com/asset/?id=14673295386"
local fw2 = "http://www.roblox.com/asset/?id=14673304582"
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local dec = character:WaitForChild("HumanoidRootPart"):WaitForChild("BillboardGui"):WaitForChild("ImageLabel")
local aaa = game:GetService("UserInputService")
aaa.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.S then
dec.Image = fw1
task.wait(.5)
dec.Image = fw2
task.wait(.5)
end
end)
You could probably also use rbxassetid:// with these too but I didn’t just incase it wouldn’t work.
thank you so much! works great. one thing, i have a loop to repeat the walking frames over and over but i don’t know how to make the loop cease after the button has being pressed. do you know what i would add?
if input.KeyCode == Enum.KeyCode.S then
while true do
dec.Image = fw1
task.wait(.5)
dec.Image = fw2
task.wait(.5)
end
end
end)
hey again! so im adding all of the sprites for the different but now im running into an issue where it works great with the S key sprites but when i press W for the backwards sprites, they go invisible just like what was happening before, but this time i have them formatted correctly
local fw1 = "http://www.roblox.com/asset/?id=14673295386"
local fw2 = "http://www.roblox.com/asset/?id=14673304582"
local fw = "http://www.roblox.com/asset/?id=14673293513"
local bw1 = "http://www.roblox.com/asset/?id=14673772477"
local bw2 = "http://www.roblox.com/asset/?id=14673775009"
local bw = "http://www.roblox.com/asset/?id=14673766920"
local rw1 = "http://www.roblox.com/asset/?id=14674241566"
local rw2 = "http://www.roblox.com/asset/?id=14674238809"
local right = "http://www.roblox.com/asset/?id=14674245898"
local lw1 = "http://www.roblox.com/asset/?id=14674233268"
local lw2 = "http://www.roblox.com/asset/?id=14674236949"
local left = "http://www.roblox.com/asset/?id=14674230583"
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local dec = character:WaitForChild("HumanoidRootPart"):WaitForChild("BillboardGui"):WaitForChild("ImageLabel")
local aaa = game:GetService("UserInputService")
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(inputObject, gameProcessed)
if gameProcessed then return end
if inputObject.KeyCode == Enum.KeyCode.S then
while UserInputService:IsKeyDown(Enum.KeyCode.S) do
dec.Image = fw1
task.wait(.3)
dec.Image = fw2
task.wait(.3)
if UserInputService:IsKeyDown(Enum.KeyCode.S) == false then
dec.Image = fw
end
end
end
if inputObject.KeyCode == Enum.KeyCode.W then
while UserInputService:IsKeyDown(Enum.KeyCode.W) do
dec.Image = bw1
task.wait(.3)
dec.Image = bw2
task.wait(.3)
end
end
end)
Formatting it isn’t enough. You need to put the actual decal id (just the number) into an ImageLabel, wait for it to convert, and then copy that converted id. I’ll convert these ones for you too.
Code:
--//Services
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
--//Variables
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local dec = character:WaitForChild("HumanoidRootPart"):WaitForChild("BillboardGui"):WaitForChild("ImageLabel")
--//Controls
local fw1 = "rbxassetid://14673295386"
local fw2 = "rbxassetid://14673304582"
local fw = "rbxassetid://14673293513"
local bw1 = "rbxassetid://14673772440"
local bw2 = "rbxassetid://14673774972"
local bw = "rbxassetid://14673766867"
local rw1 = "rbxassetid://14674241501"
local rw2 = "rbxassetid://14674238774"
local right = "rbxassetid://14674245838"
local lw1 = "rbxassetid://14674233233"
local lw2 = "rbxassetid://14674236885"
local left = "rbxassetid://14674230540"
--//Functions
UserInputService.InputBegan:Connect(function(inputObject, gameProcessed)
if gameProcessed then return end
if inputObject.KeyCode == Enum.KeyCode.S then
while UserInputService:IsKeyDown(Enum.KeyCode.S) do
dec.Image = fw1
task.wait(.3)
dec.Image = fw2
task.wait(.3)
if UserInputService:IsKeyDown(Enum.KeyCode.S) == false then
dec.Image = fw
end
end
end
if inputObject.KeyCode == Enum.KeyCode.W then
while UserInputService:IsKeyDown(Enum.KeyCode.W) do
dec.Image = bw1
task.wait(.3)
dec.Image = bw2
task.wait(.3)
end
end
end)
ohh okay awesome!! works great. last thing, do you know how i can instantly cease the sprites from going after the key has been lifted? after i lift the key for either one, it plays for a second extra which causes some issues.
--//Services
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
--//Variables
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local dec = character:WaitForChild("HumanoidRootPart"):WaitForChild("BillboardGui"):WaitForChild("ImageLabel")
--//Controls
local fw1 = "rbxassetid://14673295386"
local fw2 = "rbxassetid://14673304582"
local fw = "rbxassetid://14673293513"
local bw1 = "rbxassetid://14673772440"
local bw2 = "rbxassetid://14673774972"
local bw = "rbxassetid://14673766867"
local rw1 = "rbxassetid://14674241501"
local rw2 = "rbxassetid://14674238774"
local right = "rbxassetid://14674245838"
local lw1 = "rbxassetid://14674233233"
local lw2 = "rbxassetid://14674236885"
local left = "rbxassetid://14674230540"
--//Functions
UserInputService.InputBegan:Connect(function(inputObject, gameProcessed)
if gameProcessed then return end
if inputObject.KeyCode == Enum.KeyCode.S then
while UserInputService:IsKeyDown(Enum.KeyCode.S) do
dec.Image = fw1
task.wait(.3)
if not UserInputService:IsKeyDown(Enum.KeyCode.S) then
break
end
dec.Image = fw2
task.wait(.3)
end
dec.Image = fw
end
if inputObject.KeyCode == Enum.KeyCode.W then
while UserInputService:IsKeyDown(Enum.KeyCode.W) do
dec.Image = bw1
task.wait(.3)
if not UserInputService:IsKeyDown(Enum.KeyCode.W) then
break
end
dec.Image = bw2
task.wait(.3)
end
end
end)