I want to make an image of a gun switch to an image of a fired gun for a few seconds when I left click, then switch back to the original image. How would I do this?
Put this in a local script:
local image = --whatever location your image is in
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button1Down:Connect(function()
image.Image = -- whatever image id
wait(amount of seconds)
image.Image = -- whatever image id
end)
When I left clicked it didn’t change to the fired gun image. I put the code in the gun image label.
Here is the code that you gave me with the image IDs and image location just in case I did something wrong.
local image = game.StarterGui.GunGui.GunFrame.Gun
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button1Down:Connect(function()
image.Image = 7100685488 -- whatever image id
wait(1)
image.Image = 7100503718 -- whatever image id
end)
Check your output and check for any errors.
Did you use a module script for this. If not, this is completely unrelated.
I used a local script for this.
Okay, the error is completely unrelated then.
Your referencing the starter Gui instead of the players player gui
local Player = game.Players.LocalPlayer
local GunGui = Player:WaitForChild("PlayerGui"):WaitForChild("GunGui")
local image = GunGui.GunFrame.Gun
Replace the top with this, and it should work.
I replaced the top with that and when I left click the gun disappears instead of switching to the other image that I want to appear.
Here is the code if I did something wrong again.
local Player = game.Players.LocalPlayer
local GunGui = Player:WaitForChild("PlayerGui"):WaitForChild("GunGui")
local image = GunGui.GunFrame.Gun
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button1Down:Connect(function()
image.Image = 7100685488 -- whatever image id
wait(0.5)
image.Image = 7100503718 -- whatever image id
end)
I replaced the top with that and when I left click the gun disappears instead of switching to the other image that I want to appear.
Here is the code if I did something wrong again.
local Player = game.Players.LocalPlayer
local GunGui = Player:WaitForChild("PlayerGui"):WaitForChild("GunGui")
local image = GunGui.GunFrame.Gun
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button1Down:Connect(function()
image.Image = 7100685488 -- whatever image id
wait(0.5)
image.Image = 7100503718 -- whatever image id
end)
Did it have any errors? (Character limit)
You cannot just put the ID in and expect it to work. It needs to be formatted properly.
Try this
local Player = game.Players.LocalPlayer
local GunGui = Player:WaitForChild("PlayerGui"):WaitForChild("GunGui")
local image = GunGui.GunFrame.Gun
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button1Down:Connect(function()
image.Image = "rbxassetid://7100685488" -- whatever image id
wait(0.5)
image.Image = "rbxassetid://7100503718" -- whatever image id
end)
Thank you for telling me this! It works now but it doesn’t appear where I want it to be. Is there a way to make it appear a different size and in a different place since it appears smaller that the other image and farther to the right.
Are you using an ImageLabel correct?
I think so. I have my image label positioned where I want it and the size is correct but when I left click the second image is smaller than the first.
You may need to adjust the the size and position for the second image in the script.
How would I change the size and position using the script?