Highlight Every Time When Attribute Set to True

So, I want to make when attribute is set to true, I want to create a highlight that the whole server can see it.

However, I want to use TweenService so it looks better. But, I feel like it too slow when you change the attribute fast. I only want to create highlight when IFrame is true, however, when I try destroy it when it false. It also shows the following:

I want to use it globally but roblox appear to be dumb:
image

How can I solve this?

The following script runs when attribute changes:

local replicatedStorage = game:GetService("ReplicatedStorage")
local tweenService = game:GetService("TweenService")

local remote = replicatedStorage.Remotes:WaitForChild("AttributeChanged")

remote.OnServerEvent:Connect(function(player, character)
	if character:GetAttribute("IFrame") == true then
		highlight = Instance.new("Highlight", character)

		highlight.Name = "IFrameHighlight"

		highlight.DepthMode = Enum.HighlightDepthMode.Occluded

		highlight.FillColor = Color3.fromRGB(255, 255, 255)
		highlight.OutlineColor = Color3.fromRGB(255, 255, 255)

		highlight.FillTransparency = 1
		highlight.OutlineTransparency = 1
		
		tweenService:Create(highlight, TweenInfo.new(1), {FillTransparency = 0.75}):Play()
		tweenService:Create(highlight, TweenInfo.new(1), {OutlineTransparency = 0}):Play()
	elseif character:GetAttribute("IFrame") == false and highlight then
		tweenService:Create(highlight, TweenInfo.new(1), {FillTransparency = 1}):Play()
		tweenService:Create(highlight, TweenInfo.new(1), {OutlineTransparency = 1}):Play()
		task.wait(1)
		highlight:Destroy()
	end
end)

you have to use the _G. prefix when setting, calling, and changing global variables

What for all scripts, not just the script.

every script that uses the variable has to put the prefix

Don’t think it helping

you have to use the prefix for every single time you reference the variable. all “highlight” with the lines under them, you have to put _G. before each one. not only one time in the whole script

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.