What's wrong with this script?

  1. What do I want to achieve?

I want to make a “notificiation” that shows up when you click the left mouse button. (For a clicker game)

  1. What is the issue?

The script doesn’t work at all, I don’t even get any types of error messages.

  1. What solutions have I tried so far?
  • Trying it with a Remote Event
  • Instead of position changes, i had 8 TextLabels which should randomly get visible
  • Asking ChatGPT

If it’s an obvious mistake, i’m very sorry. I’m a beginner : )

That’s the script:

local T = script.Parent.TextLabel
local UIS = game:GetService("UserInputService")


function getRandomNumber()
	local randomIndex = math.random(1, 8)
	X = randomIndex
	return X
end





UIS.InputBegan:connect(function(input,gameProcessedEvent)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		getRandomNumber()

		local Text = T:Clone()

		if X == 1 then
			Text.Position = UDim2.new(-0.19, 0, 0.456, 0)
		elseif X == 2 then
			Text.Position = UDim2.new(-0.386, 0,0.359, 0)
		elseif X == 3 then
			Text.Position = UDim2.new(0.052, 0, 0.345, 0)
		elseif X == 4 then
			Text.Position = UDim2.new(0.094, 0, 0.608, 0)
		elseif X == 5 then
			Text.Position = UDim2.new(-0.201, 0, 0.19, 0)
		elseif X == 6 then
			Text.Position = UDim2.new(-0.419, 0, 0.116, 0)
		elseif X == 7 then
			Text.Position = UDim2.new(-0.401, 0, 0.602, 0)
		elseif X == 8 then
			Text.Position = UDim2.new(0.17, 0, 0.135, 0)
		end


		Text.Visible = true
		wait(3)
		Text.Visible = false
	end
end)


Does anybody have a clue what the issue can be, or even has a better alternative?
Thanks for any help!

4 Likes

You didn’t define X, all you have is getRandomNumber(), you have to do local X=getRandomNumber()

3 Likes

Didn’t work. I defined X before in the function though

3 Likes

Nope somehow not a single Error! : (

3 Likes

I know that isn’t the only problem because no way the script would run and not error. I don’t think the code in the event is running, do a print()

2 Likes

Is this a LocalScript? If it is, at the top, try using WaitForChild(). The client might not have had time to register the label.

local T = script.Parent:WaitForChild("TextLabel")

3 Likes

Yes it is. Okay i’ll try it! WAit a sec…

2 Likes

Both things didn’t work… And again no error message xd

1 Like

Can I ask where this script is located in the Explorer? (just a screenshot) :smiley:

1 Like

I already said the exact same but you didn’t listen. If that was the problem though it would be erroring, therefore the script in the event isn’t running at all

2 Likes

StarterGui/Texts (Is a ScreenGUI)/

2 Likes

Oops, I kind of misread your post :sweat_smile: hence the dodgy reply after it. My bad! I’ll delete it.

3 Likes

Oh i must’ve overseen it xd what can i do to make it running?

1 Like

run this and say what prints in the output:

local T = script.Parent.TextLabel
local UIS = game:GetService("UserInputService")


function getRandomNumber()
	local randomIndex = math.random(1, 8)
	X = randomIndex
	return X
end





UIS.InputBegan:connect(function(input,gameProcessedEvent)
print('one')
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
print('two')
		local X = getRandomNumber()

		local Text = T:Clone()

		if X == 1 then
			Text.Position = UDim2.new(-0.19, 0, 0.456, 0)
		elseif X == 2 then
			Text.Position = UDim2.new(-0.386, 0,0.359, 0)
		elseif X == 3 then
			Text.Position = UDim2.new(0.052, 0, 0.345, 0)
		elseif X == 4 then
			Text.Position = UDim2.new(0.094, 0, 0.608, 0)
		elseif X == 5 then
			Text.Position = UDim2.new(-0.201, 0, 0.19, 0)
		elseif X == 6 then
			Text.Position = UDim2.new(-0.419, 0, 0.116, 0)
		elseif X == 7 then
			Text.Position = UDim2.new(-0.401, 0, 0.602, 0)
		elseif X == 8 then
			Text.Position = UDim2.new(0.17, 0, 0.135, 0)
		end


		Text.Visible = true
		wait(3)
		Text.Visible = false
	end
end)
2 Likes

The problem is that you need to put the Text parent to the ScreenGui

Text.Parent = script.Parent (ScreenGui)

1 Like

It prints both one and two. I need more word xd

1 Like

Try this :

local T = script.Parent.TextLabel
local UIS = game:GetService("UserInputService")


function getRandomNumber()
	local randomIndex = math.random(1, 8)
	X = randomIndex
	return X
end





UIS.InputBegan:connect(function(input,gameProcessedEvent)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		getRandomNumber()

		local Text = T:Clone()
		
		Text.Parent = script.Parent

		if X == 1 then
			Text.Position = UDim2.new(-0.19, 0, 0.456, 0)
		elseif X == 2 then
			Text.Position = UDim2.new(-0.386, 0,0.359, 0)
		elseif X == 3 then
			Text.Position = UDim2.new(0.052, 0, 0.345, 0)
		elseif X == 4 then
			Text.Position = UDim2.new(0.094, 0, 0.608, 0)
		elseif X == 5 then
			Text.Position = UDim2.new(-0.201, 0, 0.19, 0)
		elseif X == 6 then
			Text.Position = UDim2.new(-0.419, 0, 0.116, 0)
		elseif X == 7 then
			Text.Position = UDim2.new(-0.401, 0, 0.602, 0)
		elseif X == 8 then
			Text.Position = UDim2.new(0.17, 0, 0.135, 0)
		end


		Text.Visible = true
		wait(3)
		Text.Visible = false
	end
end)
2 Likes

IT WORKS!! Thank you very much xd

2 Likes

But what was the issue? xd i want to know this

1 Like

the frame wasn’t parented to the screenGui, it seems like it was parented to the script which can’t be visible

2 Likes