how to make variable

Solutions on MaxInterview for how to make variable by the best coders in the world

showing results for - "how to make variable"
Martina
09 Jan 2017
1local UIS = game:GetService("UserInputService")
2local RS = game:GetService("RunService")
3local ReplicatedStorage = game:GetService("ReplicatedStorage")
4local RemoteEvents = ReplicatedStorage.RemoteEvents
5local Player = game.Players.LocalPlayer
6local Camera = workspace.CurrentCamera
7local DefaultSize = script.Parent.Size
8
9function determineClosest(EggsAvailable)
10	local CurrentClosest = nil
11	local ClosestDistance = script.Parent.MaxMagnitude.Value
12	for i,v in pairs(EggsAvailable) do
13		local Egg = workspace.Eggs:FindFirstChild(v)
14		local mag = (Egg.UIanchor.Position-Player.Character:WaitForChild("HumanoidRootPart").Position).Magnitude
15		if mag <= ClosestDistance then
16			CurrentClosest = Egg
17			ClosestDistance = mag
18		end
19	end
20	return CurrentClosest
21end
22
23RS.RenderStepped:Connect(function()
24	if Player.Character:FindFirstChild("Humanoid") then
25		if Player.Character.Humanoid.Health ~= 0 then
26			local EggsAvailable = {}
27			local CameraRatio = ((Camera.CFrame.Position - Camera.Focus.Position).Magnitude)/11
28			script.Parent.Visible = false
29			for i,v in pairs(game.Workspace.Eggs:GetChildren()) do
30				local mag = (v.UIanchor.Position-Player.Character:WaitForChild("HumanoidRootPart").Position).Magnitude
31				if mag <= script.Parent.MaxMagnitude.Value then
32					EggsAvailable[#EggsAvailable+1] = v.Name
33				end
34			end
35			if #EggsAvailable == 1 then
36				local Egg = workspace.Eggs:FindFirstChild(EggsAvailable[1])
37				local WSP = game.Workspace.CurrentCamera:WorldToScreenPoint(Egg.UIanchor.Position)
38				script.Parent.Visible = true
39				script.Parent.Position = UDim2.new(0,WSP.X,0,WSP.Y)
40				script.Parent.CurrentTarget.Value = Egg.Name
41			elseif #EggsAvailable > 1 then
42				local Egg = determineClosest(EggsAvailable)
43				local WSP = game.Workspace.CurrentCamera:WorldToScreenPoint(Egg.UIanchor.Position)
44				script.Parent.Visible = true
45				script.Parent.Position = UDim2.new(0,WSP.X,0,WSP.Y)
46				script.Parent.CurrentTarget.Value = Egg.Name
47			elseif #EggsAvailable == 0 then
48				script.Parent.CurrentTarget.Value = "None"
49			end
50			script.Parent.Size = UDim2.new(DefaultSize.X.Scale/CameraRatio, DefaultSize.X.Offset, DefaultSize.Y.Scale/CameraRatio, DefaultSize.Y.Offset)
51		end
52	end
53end)
similar questions
queries leading to this page
how to make variable