In this screenshot, shows it doing a function
This screenshot shows the function, which fires a event
this last image shows what the event does, which shows some text on the players screen.
This code works, but only sometimes. It’s weird. sometimes it works as intended while other times, no text shows up, which is weird as there should be text, regardless of if the missile hits or not.
Please paste the code here and wrap it in 3 backticks (`) next time as it will be easier to copy code and help you
Anyways, the problem is the 3-second-wait after showing text. Since you are firing the events rapidly they overlap eachother causing the text to show and hide, sometimes no text showing up. A timer attribute is needed to limit hiding the text:
script:SetAtrribute("Timer", 0) -- setup timer atrribute
ReplicatedStorage.Kill1.Event:Connect(function()
text.Text = "TARGET HIT"
text.TextTransparency = 0
text.BackgroundTransparency = 0.5
if script:GetAtrribute("Timer") > 0 then return end -- stop if there is an event trying to turn the text off
script:SetAttribute("Timer", 3)
end)
ReplicatedStorage.Miss1.Event:Connect(function()
text.Text = "TARGET MISSED"
text.TextTransparency = 0
text.BackgroundTransparency = 0.5
if script:GetAtrribute("Timer") > 0 then return end -- stop if there is an event trying to turn the text off
script:SetAttribute("Timer", 3)
end)
script:GetAttributeChangedSignal("Timer"):Connect(function() -- detect when timer changes
if script:GetAttribute("Timer") <= 0 then
text.TextTransparency = 1
text.BackgroundTransparency = 1
end
end)
while true do -- set up timer
task.wait(1)
local currenttime = script:GetAttribute("Timer")
if currenttime > 0 then -- reduce timer if timer > 0
script:SetAttribute("Timer", currenttime - 1)
end
end