I am very happy to announce that I created my first Objective system!
It is my first so it is not really push and it is in customer (I was always told not to trust the customer, I do not apply this advice…) Well it is the prototype 1 so I intend to improve I have only 5 months of experience…
if English is bad, let me know, I am French
- I have 5 months of experiance
- Please give feedback!
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local player = game.Players.LocalPlayer
local character = player.Character
local humanoidRootPart = character.HumanoidRootPart
local playerGui = player:WaitForChild("PlayerGui")
local topGui = playerGui:WaitForChild("TopGui")
local cloneObjectifFrame = game.ReplicatedStorage.MainClone.ObjectifFrame:Clone()
local highLight = game.ReplicatedStorage.MainClone.Highlight:Clone()
local connect
local Objectif = {}
Objectif.__index = Objectif
function Objectif.new(goal, objectifType, object)
local self = setmetatable({}, Objectif)
self.Goal = goal
self.ObjectifType = objectifType
self.Object = object
return self
end
function Objectif:Create()
print(self.Goal)
local goalText = cloneObjectifFrame.GoalText
goalText.Text = tostring(self.Goal)
cloneObjectifFrame.Parent = topGui
TweenService:Create(cloneObjectifFrame, TweenInfo.new(1), {Size = UDim2.new(0.433, 0,0.104, 0)}):Play()
highLight.Parent = self.Object
highLight.Adornee = self.Object
if self.ObjectifType == "Found" then
connect = RunService.RenderStepped:Connect(function()
if (humanoidRootPart.Position - self.Object.PrimaryPart.Position).Magnitude <= 50 then
connect:Disconnect()
Objectif:Destroy()
else
return
end
end)
end
if self.ObjectifType == "Kill" then
connect = RunService.RenderStepped:Connect(function()
if self.Object.Humanoid.Health <= 0 then
connect:Disconnect()
Objectif:Destroy()
else
return
end
end)
end
end
function Objectif:Destroy()
local tween = TweenService:Create(cloneObjectifFrame, TweenInfo.new(1), {Size = UDim2.new(0,0,0,0)})
highLight:Destroy()
tween:Play()
tween.Completed:Connect(function()
cloneObjectifFrame:Destroy()
end)
end
return Objectif