So, basically, I am making a popup and I am trying to change the text of a Texlabel depending on a parts name, but it keeps changing to names the for different parts.
My Script:
local v1 = game.Players.LocalPlayer
local v2 = game.Workspace:WaitForChild(v1.Name)
local v3 = nil
local v4 = nil
local v5 = game.ReplicatedStorage:WaitForChild("Prompt"):Clone()
function Sound1()
local frame = script.Parent
v5.Button:TweenSizeAndPosition(UDim2.new(0.768, 0,0.768, 0), UDim2.new(0.116, 0,0.115, 0), "Out","Quad",.2,true)
local v6 = script.Pop
v6:Play()
wait(.75)
v6:Pause()
end
function Sound2()
v5.Button:TweenSizeAndPosition(UDim2.new(0.72, 0,0.72, 0), UDim2.new(0.119, 0,0.14, 0), "Out","Quad",.1,true)
local v7 = script.Pop2
v7:Play()
wait(.75)
v7:Pause()
end
function DSize()
v5.Button:TweenSizeAndPosition(UDim2.new(0.25, 0,0.25, 0), UDim2.new(0.354, 0,0.374, 0), "Out","Quad",.1,true)
end
v5.Parent = v1:WaitForChild("PlayerGui")
repeat
wait(0.05)
if v1.Character.Humanoid.SeatPart == nil and game:IsLoaded() then
local parts = game.Workspace:GetDescendants()
for _,p in pairs(parts) do
if p.Name == "EPart" then
if p.Name == "EPart" then
if p.Parent.Name == "NPC" then -- were i change the text!
v5.Action.Text = "Talk"
end
if p.Parent.Name == "Box" then
v5.Action.Text = "Search Box"
end
if p.Parent.Name == "Crate" then
v5.Action.Text = "Search Crate"
if p.Parent.Name == "Garbage" then
v5.Action.Text = "Search Grabage Bin"
if p.Parent.Name == "Barrel" then
v5.Action.Text = "Search Barrel"
end
end
end
end
local Magnitude = (p.Parent.Position-v2.HumanoidRootPart.Position).magnitude
if Magnitude < 5 then --if they are within a certain distance
if v3 == nil then
v3 = p.Parent
v4 = Magnitude
v5.Adornee = v3
v5.Enabled = true
v5.ClosestPart.Value = v3
Sound1()
elseif v3 ~= nil and v3 ~= p then
if Magnitude < v4 then
v3 = nil
v4 = nil
v5.Enabled = false
wait(0.025)
v3 = p.Parent
v4 = Magnitude
v5.Adornee = v3
v5.Enabled = true
v5.ClosestPart.Value = v3
end
end
elseif Magnitude >= 5 or Magnitude >= v4 then
if p.Parent == v3 then
DSize()
wait(.1)
v3 = nil
v5.Adornee = nil
v5.Enabled = false
v5.ClosestPart.Value = nil
Sound2()
elseif v3 == nil then
v4 = nil
v5.Adornee = nil
v5.Enabled = false
v5.ClosestPart.Value = nil
end
end
end
end
else
if game:IsLoaded() then
v3 = nil
v5.Adornee = nil
v5.ClosestPart.Value = nil
v5.Enabled = false
v4 = nil
end
end
until script.Disabled == true