Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

why does the gui not move to my mouse's position?

Asked by
wookey12 174
6 years ago
Edited 6 years ago

i have a script where when you position your mouse over any part that is lootable, it brings a textlabel to your mouse's position, and displays the name of the part. but for some reason it's not working. the script is located inside of a screengui. here is my script:

local plr = script.Parent.Parent.Parent
local Char = plr.Character
local label = script.Parent.TextLabel
local mouse = plr:GetMouse()
local Lootables = {"Small Stone", "Large Stone", "Gold"}

mouse.Move:connect(function()
    if mouse.Target.Name == Lootables then
    print(mouse.Target.Name)
    label.Text = mouse.Target.Name
    label.Position = UDim2.new(0,mouse.X,0,mouse.Y)
    end
end)

I think the problem is in line 8.

0
nothing to do with this bit why is player defined as parent parent parent User#19524 175 — 6y

1 answer

Log in to vote
0
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
6 years ago
Edited 6 years ago

It's indeed in Line 8.

Currently you're just checking if the Name equals an entire table, which is never going to work, seeing that one is a string, and the other is a table.

you should do if mouse.Target and Lootables[mouse.Target.Name] then to check if the Target is in the loot table.

I also suggest changing your variable from Lootables to LootTables (double t)

Ad

Answer this question