Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I make the image + text change onclick?

I want to know how I can change the text and mesh texture onclick? like for example the left button does "-1" and the right does "+1"

local gift = script.Parent.Parent.Gift
local mesh = gift.Mesh
local right = script.Parent.Parent.Right
local click = right.ClickDetector
local text = script.Parent.Parent.InformationBlock
infotext = text.InfoGui.InfoText.Parent
local id = "rbxassetid://"
local sn = 1
texture = {189783253,189748284}
function onClicked()		
sn = sn + 1
	if sn > #texture then sn = 1 end
	mesh.TextureId = id..texture[sn]
while wait() do
for i=1,#texture do
	print(i) -- test what shows up
if i == 1 then
	text.InfoGui.InfoText.Text = "Gift 1"
	print("Gift1")
elseif i == 2 then
	text.InfoGui.InfoText.Text = "Gift 2"
	print("Gift2")
end
end
end
end

The text thing only works once, if it's possible.

2 comments

0

Use two scripts, one that changes it when left is touched, and one for right. You dont need to over complicate it.

0

That's what I did.

1 answer

This is how I went about it, I left out the portion of the GUI as I was unsure how you had your set up, I hope this helped in some sort?

local ID = "rbxassetid://"

local Gifts = { Gift1 = {Name = 'Gift One', Texture = 189783253}, 
      Gift2 = {Name = 'Gift Two', Texture = 189748284} }

local GiftOn = 1
local MaxGifts = 2

if game.Workspace:FindFirstChild("Gift") ~= nil then
	game.Workspace.Gift:remove()
end

local Gift = Instance.new("Part", game.Workspace)
	Gift.FormFactor = "Custom"
	Gift.Size = Vector3.new(2,2,2)
	Gift.Anchored = true
	Gift.Name = "Gift"
	local Mesh = Instance.new("SpecialMesh", Gift)
		Mesh.MeshType = "FileMesh"
		Mesh.MeshId = "http://www.roblox.com/asset/?id=1237207"
		Mesh.TextureId = ID..(Gifts["Gift"..GiftOn].Texture)
	local ClickDet = Instance.new("ClickDetector", Gift)
		ClickDet.MaxActivationDistance = 10

function Clicked()
	GiftOn = GiftOn + 1
	if GiftOn > MaxGifts then
		GiftOn = 1
	end
		Mesh.TextureId = ID..(Gifts["Gift"..GiftOn].Texture)
end
ClickDet.MouseClick:connect(Clicked)

1 comment

0

It somehow, but It doesn't seem to go in the order I wanted and I used two parts to change the gift texture. I wanted the texture to change to 2 once clicked the right button and back to 1 once the left button is pressed.

This discussion is preserved as it was. New answers, comments, and votes are closed.