I am trying to make a goal system. The script works fine once weather the OrangeHitBox or BlueHitBox is touched by the part but doesn’t work on the other one if the other part was touched first. When I use the Print Debug method it prints the first time but not when the other one it touched. Also it only works once. How do I fix this
-- SERVER SCRIPT LOCATIED IN GOALALERT
-- <<VERIABLES>>
local MainFrame = script.Parent:WaitForChild("MainFrame")
local Text_Red = MainFrame:WaitForChild("Red")
local Text_Blue = MainFrame:WaitForChild("Blue")
local part = workspace:WaitForChild("partA")
-- <<FUNCTIONS>>
local function onHit(hit)
if hit.Name == "OHitBox" then
MainFrame.Visible = true
Text_Blue.Visible = true
end
if hit.Name == "BHitBox" then
MainFrame.Visible = true
Text_Red.Visible = true
end
task.wait(2)
MainFrame.Visible = false
Text_Red.Visible = false
Text_Blue.Visible = false
end
-- <<CONNECTIONS>>
part.Touched:Connect(onHit)
I have 2 goals per map and I have five maps. They easiest way to fix this is by adding a script to each of them and when they are touched the UI comes up.
But the other way I do not know how to do it. It would be to get all of the goals and make one script that detects when one of them are hit and the UI comes Up. But I do not know how to do this. I prefer to do it this way
Then try replacing the script with a localscript then make a RemoteEvent and call it HitEvent then put it in replicated storage. Then, put a script in SSS (ServerScriptService) Next replace the function in the LocalScript with this:
-- keep the part variable but delete the other variables...
function onHit(hit)
game.ReplicatedStorage.HitEvent:FireServer(hit)
end
part.Touched:Connect(onHit)
For the serverscript, do:
local event = game.ReplicatedStorage.HitEvent
event.OnServerEvent:Connect(function(ply,hit)
if hit:IsA("BasePart") and hit.Name == "OHitBox" then
-- code here
end
if hit:IsA("BasePart") and hit.Name == "BHitBox" then
-- code here
end
end)
If that didn’t work or printed out an error please send back a message
When I tried this nothing happened, but it gave me an idea (that i don’t know how to do). What you gave me was a remote event that fired the event. I have another script that destroys the part when it touches the HitBoxes.
My idea is fire a remote event from the other script and so forth but I don’t know how to fire a remote event on server side to server side
Im pretty sure you dont even need a script in the screengui. Just put it somewhere in serverstorage and remove the remoteevent and local script and paste you’re original code (from where you first started this post) and put it in the serverscript and modify some things around
Ok I got it down to the script below. The problem is that I the UI stays up for a very long time and then goes a way. I want it to wait 3 seconds and the disappear. How do I fix this
local part= script.Parent
local function showUI(frame)
for _, Player in pairs(game.Players:GetChildren()) do
Player.PlayerGui.GoalAlert.MainFrame.Visible = true
Player.PlayerGui.GoalAlert.MainFrame[frame].Visible = true
wait(3)
Player.PlayerGui.GoalAlert.MainFrame.Visible = false
Player.PlayerGui.GoalAlert.MainFrame[frame].Visible = false
end
end
local function oHitBox()
showUI("Blue")
end
local function bHitBox()
showUI("Red")
end
part.Touched:Connect(function(hit)
if hit.Name == "OHitBox" then
oHitBox()
elseif hit.Name == "BHitBox" then
bHitBox()
end
end)