I need help to solve this problem, so i made a script on my game where if u get close to an object whit a proximity prompt on it it does a fade animation using tween service and a highlight but if the player approaches and moves away very quickly from the object it glitches out
here is an example :
this is what happens if the player does it too fast
this is the code
local ProximityPromptService = game:GetService("ProximityPromptService")
local TweenService = game:GetService("TweenService")
local player = game.Players.LocalPlayer
--effects
local particle = script.ParticleEmitter
local light = script.PointLight
---{Functions}---
ProximityPromptService.PromptShown:Connect(function(ProximityPrompt)
if ProximityPrompt.Parent and ProximityPrompt.Parent:IsA("BasePart") then
local Highlight = Instance.new("Highlight", ProximityPrompt.Parent); Highlight.FillColor = Color3.fromRGB(255, 255, 255); Highlight.FillTransparency = 1; Highlight.OutlineTransparency = 1
particle:Clone().Parent = Highlight.Parent
local light = light:Clone()
light.Parent = Highlight.Parent
local goal = {}
goal.OutlineTransparency = 0
local goal2 = {}
goal2.Brightness = 0.6
local tweenInfo = TweenInfo.new(0.5)
local tweenInfo2 = TweenInfo.new(0.5)
local tween2 = TweenService:Create(light, tweenInfo2, goal2)
local tween = TweenService:Create(Highlight, tweenInfo, goal)
tween:Play()
tween2:Play()
player.PlayerGui.InteractButton.TextLabel.Text = "(".. ProximityPrompt.KeyboardKeyCode.Name .. ")"
player.PlayerGui.InteractButton.Enabled = true
end
end)
ProximityPromptService.PromptHidden:Connect(function(ProximityPrompt)
if ProximityPrompt.Parent and ProximityPrompt.Parent:FindFirstChildOfClass("Highlight") then
local Highlight = ProximityPrompt.Parent:FindFirstChildOfClass("Highlight")
player.PlayerGui.InteractButton.Enabled = false
local particle = Highlight.Parent:FindFirstChild("ParticleEmitter")
local light = Highlight.Parent:FindFirstChild("PointLight")
particle.Enabled = false
local goal = {}
goal.OutlineTransparency = 1
local goal2 = {}
goal2.Brightness = 0
local tweenInfo = TweenInfo.new(0.5)
local tweenInfo2 = TweenInfo.new(0.5)
local tween2 = TweenService:Create(light, tweenInfo2, goal2)
local tween = TweenService:Create(Highlight, tweenInfo, goal)
tween:Play()
tween2:Play()
tween.Completed:Connect(function()
particle:Destroy()
Highlight:Destroy()
light:Destroy()
end)
end
end)
thanks!