Image doesnt change

hii!! i’ve been trying to get a custom image for a tool buut… not working as expected. even though i can set the image in studio, it doesnt appear when playtesting OR in the game. heres the script… PLEASE HELP. IVE BEEN TRYING TO MAKE IT WORK FOR LIKE 2 DAYS.

local plr = game.Players.LocalPlayer
local tool = script.Parent
local inputs = game:GetService("UserInputService")
local currentspell = tool.currentspell
local event = tool.changespell
local gui = tool.spellpage
local mouse
local check1 = tool.check1
local check2 = tool.check2
local check3 = tool.check3

local nospell = "rbxassetid://119375355084853"
local pumpimage = "http://www.roblox.com/asset/?id=92445415345001"
local skelimage = "http://www.roblox.com/asset/?id=120653858123648"
local shieldimage = "http://www.roblox.com/asset/?id=97128960276705"

local char

local shieldan = tool:WaitForChild("shield")
local pumpkan = tool:WaitForChild("pumpkin")
local summonan = tool:WaitForChild("summon")

local shielda
local pumpa
local summona

local curmouse
local currentmousefunc

--summon to pumpkinball to shield "rbxassetid://76568679516657"

function setMousicon(icon)
	if plr.PlayerGui:FindFirstChild("mausicon") then
		print("ooh")
		curmouse:FindFirstChild("icon").Image = icon
	end
end

inputs.InputBegan:Connect(function(inp, processed)
	if processed or tool.equipped.Value == false then
		return
	end
	
	if inp.KeyCode == Enum.KeyCode.E then
		if currentspell.Value == "summon" then
			if check2.Value then
				setMousicon(pumpimage)
			else
				setMousicon(nospell)
			end
			event:FireServer("pumpkin")
		end
		if currentspell.Value == "pumpkin" then
			if check3.Value then
				setMousicon(shieldimage)
			else
				setMousicon(nospell)
			end
			event:FireServer("shield")
		end
		if currentspell.Value == "shield" then
			if check1.Value then
				setMousicon(skelimage)
			else
				setMousicon(nospell)
			end
			event:FireServer("summon")
		end
	end
	if inp.KeyCode == Enum.KeyCode.Q then
		if currentspell.Value == "shield" then
			if check2.Value then
				setMousicon(pumpimage)
			else
				setMousicon(nospell)
			end
			event:FireServer("pumpkin")
		end
		if currentspell.Value == "pumpkin" then
			if check1.Value then
				setMousicon(skelimage)
			else
				setMousicon(nospell)
			end
			event:FireServer("summon")
		end
		if currentspell.Value == "summon" then
			if check3.Value  then
				setMousicon(shieldimage)
			else
				setMousicon(nospell)
			end
			event:FireServer("shield")
		end
	end
end)

check1.Changed:Connect(function(val)
	if currentspell.Value == "summon" then
		if not val then
			setMousicon(nospell)
			summona:Play()
		end
		if val then
			setMousicon(skelimage)
		end
	end
end)
check2.Changed:Connect(function(val)
	if currentspell.Value == "pumpkin" then
		if not val then
			setMousicon(nospell)
			pumpa:Play()
		end
		if val then
			setMousicon(pumpimage)
		end
	end
end)
check3.Changed:Connect(function(val)
	if currentspell.Value == "shield" then
		if not val then
			setMousicon(nospell)
			shielda:Play()
		end
		if val then
			setMousicon(shieldimage)
			shielda:Stop()
		end
	end
end)

local theyloaded = false

tool.Equipped:Connect(function(maus)
	char = tool.Parent
	if not theyloaded then
		theyloaded = true
		shielda = char:FindFirstChild("Humanoid"):FindFirstChild("Animator"):LoadAnimation(shieldan)
		pumpa = char:FindFirstChild("Humanoid"):FindFirstChild("Animator"):LoadAnimation(pumpkan)
		summona = char:FindFirstChild("Humanoid"):FindFirstChild("Animator"):LoadAnimation(summonan)
	end
	
	mouse = maus
	if currentspell.Value == "summon" then
		if check1.Value then
			setMousicon(skelimage)
		else
			setMousicon(nospell)
		end
	end
	if currentspell.Value == "pumpkin" then
		if check2.Value then
			setMousicon(pumpimage)
		else
			setMousicon(nospell)
		end
	end
	if currentspell.Value == "shield" then
		if check3.Value then
			setMousicon(shieldimage)
		else
			setMousicon(nospell)
		end
	end
	gui.Parent = plr.PlayerGui
	
	curmouse = game:FindFirstChild("ReplicatedStorage"):FindFirstChild("otherstuffs"):FindFirstChild("mausicon"):Clone()
	curmouse.Parent = plr.PlayerGui
	inputs.MouseIconEnabled = false
	currentmousefunc = mouse.Move:Connect(function()
		local loc = inputs:GetMouseLocation()
		curmouse:FindFirstChild("icon").Position = UDim2.new(loc.X, loc.Y)
	end)
end)

tool.Unequipped:Connect(function()
	setMousicon("rbxasset://textures\\ArrowFarCursor.png")
	
	currentmousefunc:Disconnect()
	curmouse:Destroy()
	inputs.MouseIconEnabled = true
	
	gui.Parent = tool
end)

currentspell.Changed:Connect(function()
	gui.Frame.pagetext.Text = ("<Q "..currentspell.Value.." E>")
end)

tool.Activated:Connect(function()
	if currentspell.Value == "summon" and check1.Value then
		
	end
	if currentspell.Value == "pumpkin" and check2.Value then
		
	end
	if currentspell.Value == "shield" and check3.Value then
		
	end
end)
5 Likes

to whoever just gazes upon my posts and likes them instead of helping… please help. its still not working. i am in desperate need of help.

1 Like

could you provide some more details on what your trying to achieve with your script? as looking into the code is kinda confusing.

2 Likes

theres 3 different spells for the tool. i want to make it so that, for every single time that you use the tool (or change the spell using e or q on your keyboard) your mouse icon changes. for example: when you activate one spell your icon changes to nospell (“rbxassetid://119375355084853”) (also this runs by checking for when a checkvalue is changed) and, when you change a spell, if its on cooldown it will simply show you the nospell icon. if its not on cooldown though, it will show you the icon of the spell that has been chosen. i hope this gets the point across because… eh im not much of an explainer guy. the code should be alright because when i tried using print it worked.

alright then, sounds simple enough, i’ll try to replicate your script and see if i can get it working for you.

alright, i’ve made a script that should do what you’re trying to achieve, just put this into a localscript and place into a tool, hope this helps, let me know if you have anymore issues.

local tool = script.Parent

local player = game:GetService("Players").LocalPlayer

local mouse = player:GetMouse()

-- (from left to right) default image, 1st spell image, 2nd spell image, and 3rd spell image.

local icons = {"rbxassetid://10830675223", "rbxassetid://8652245135", "rbxassetid://13801143329", "rbxassetid://7204384248"}

local cooldowns = {0, 1, 5, 3}

mouse.Icon = icons[1]

local currentIcon = 1

local connection

local disabled = false

tool.Equipped:Connect(function()
	
	connection = game:GetService("UserInputService").InputBegan:Connect(function(input)
		
		if disabled == false then
			
			if input.KeyCode == Enum.KeyCode.Q then

				currentIcon -= 1

				if currentIcon <= 1 then

					currentIcon = 1

					mouse.Icon = icons[currentIcon]

				else
					mouse.Icon = icons[currentIcon]
				end

			end

			if input.KeyCode == Enum.KeyCode.E then

				currentIcon += 1

				if currentIcon >= 4 then

					currentIcon = 4

					mouse.Icon = icons[currentIcon]

				else
					mouse.Icon = icons[currentIcon]
				end

			end
			
		end

	end)
	
end)

local event = script.Parent.Activated

local function activated()
	
	if currentIcon > 1 then
		
		disabled = true

		xpcall(function()

			mouse.Icon = icons[1]
			
			task.wait(cooldowns[currentIcon])
			
			mouse.Icon = icons[currentIcon]

			disabled = false

		end, warn)

		event:Once(activated)
		
	end
	
end

event:Once(activated)

tool.Unequipped:Connect(function()
	
	connection:Disconnect()
	
	mouse.Icon = icons[1]
	
end)

hey uhh sorry for not replying but ive figured out the issue in my script. turns out, the mouse.Move thing i did was kinda done a bit wrong
curmouse:FindFirstChild("icon").Position = UDim2.new(loc.X, loc.Y) -- tis' the way it was before

aand this is the right way

curmouse:FindFirstChild("icon").Position = UDim2.new(0, loc.X, 0, loc.Y) -- now it doesnt set the position to millions of pixels off

Thats alright, glad you were able to figure it out, don’t forget to mark your reply as the solution.

oh right. superthirtycharacters

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.