Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Cloning gui from startgui?

Asked by
j1011 0
8 years ago

So i made an announcer gui which is now inside StarterGui, What i'm trying to achieve is when the player successfully captured the flag the gui will announce this : game.StarterGui.Announce.Frame.Txt.Text = "Fort Altipix 2.0, controlled by " ..name2.. ", is being captured by the " ..name.. "!" ------- ->>> But its not working..

See the rest of the script.

bin = script.Parent.Base
owner = script.Parent.CurrentOwner
distance = script.Parent.CaptureDistance.Value
steps = script.Parent.StepsToBottom
maxsteps = steps.Value
a = script.Parent.P4
b = script.Parent.P3
c = script.Parent.P2
d = script.Parent.P1
neutral = script.Parent.NeutralColor.Value

attackingteam = nil
defendingteam = nil

script.Parent.FlagManager.Disabled = false

players = {}

for i,v in pairs(game.Players:GetPlayers()) do
table.insert(players, v)
end

game.Players.PlayerAdded:connect(function(p) table.insert(players, p) end)

function findTeamByColor(color)
returnee = ""
for i,v in pairs(game.Teams:children()) do
if v.TeamColor == color then
returnee = v.Name
break
end
end
return returnee
end

function moveFlag(team, name, name2)
if (team ~= owner.Value) and (owner.Value ~= neutral) then
if steps.Value > 0 then
a.CFrame = a.CFrame-Vector3.new(0,7/maxsteps,0)
b.CFrame = b.CFrame-Vector3.new(0,7/maxsteps,0)
c.CFrame = c.CFrame-Vector3.new(0,7/maxsteps,0)
d.CFrame = c.CFrame-Vector3.new(0,7/maxsteps,0)
steps.Value = steps.Value-1
if steps.Value == 0 then
attackingteam = team
defendingteam = owner.Value
owner.Value = neutral
game.StarterGui.Announce.Frame.Txt.Text = "Fort Altipix 2.0, controlled by " ..name2.. ", is being captured by the " ..name.. "!"
game:service("Debris"):AddItem(m, 10)
end
end
elseif (team == owner.Value) and (owner.Value ~= neutral) then
if steps.Value < maxsteps then
a.CFrame = a.CFrame+Vector3.new(0,7/maxsteps,0)
b.CFrame = b.CFrame+Vector3.new(0,7/maxsteps,0)
c.CFrame = c.CFrame+Vector3.new(0,7/maxsteps,0)
d.CFrame = c.CFrame+Vector3.new(0,7/maxsteps,0)
steps.Value = steps.Value+1
if steps.Value == maxsteps then
owner.Value = team
end
end
elseif (team ~= owner.Value) and (owner.Value == neutral) then
if team == defendingteam then
if steps.Value > 0 then
a.CFrame = a.CFrame-Vector3.new(0,7/maxsteps,0)
b.CFrame = b.CFrame-Vector3.new(0,7/maxsteps,0)
c.CFrame = c.CFrame-Vector3.new(0,7/maxsteps,0)
d.CFrame = d.CFrame-Vector3.new(0,7/maxsteps,0)
steps.Value = steps.Value-1
if steps.Value == 0 then
game.StarterGui.Announce.Frame.Txt.Text = "Fort Altipix 2.0 has been recovered from the " ..findTeamByColor(attackingteam).. " by the " ..name.. "!"
game:service("Debris"):AddItem(m, 10)
attackingteam = nil 
defendingteam = nil
owner.Value = team
end
end
else
a.CFrame = a.CFrame+Vector3.new(0,7/maxsteps,0)
b.CFrame = b.CFrame+Vector3.new(0,7/maxsteps,0)
c.CFrame = c.CFrame+Vector3.new(0,7/maxsteps,0)
d.CFrame = d.CFrame+Vector3.new(0,7/maxsteps,0)
steps.Value = steps.Value+1
if steps.Value == maxsteps then
if defendingteam then
game.StarterGui.Announce.Frame.Txt.Text = "Outpost Infinity has been captured by the " ..name.. " from the " ..findTeamByColor(defendingteam).. "!"
else
game.StarterGui.Announce.Frame.Txt.Text = "Outpost infinity has been claimed by the " ..name.. "."
end
game:service("Debris"):AddItem(m, 10)
attackingteam = nil
defendingteam = nil
owner.Value = team
end
end
end
end

while true do
wait()
for i,v in pairs(players) do
if v.Character ~= nil then
torso = v.Character:findFirstChild("Torso")
if torso ~= nil then
if (torso.Position-bin.Position).magnitude <= distance then
if v.TeamColor ~= neutral then
moveFlag(v.TeamColor, findTeamByColor(v.TeamColor), findTeamByColor(owner.Value))
end
end
end
end
end
end

1 answer

Log in to vote
4
Answered by
DataStore 530 Moderation Voter
8 years ago

The StarterGui is a container whose contents is cloned to the spawning player's PlayerGui. After the player is spawned, there is no link between the StarterGui's GUI and the GUI which is in the player's PlayerGui (meaning that changes made to the StarterGui won't show until the player has respawned).

In order for you to display a notification on everyone's screen you'll need to iterate through the Players service and make changes to everyone's GUI (on top of changing the StarterGui's GUI). An example of how to do this is below.

function Annoucement(Text)
    game.StarterGui.Announce.Frame.Txt.Text = Text
    for _, Player in pairs(game.Players:GetPlayers()) do
        if Player:FindFirstChild("PlayerGui") and Player.PlayerGui:FindFirstChild("Announce") then
            Player.PlayerGui.Announce.Frame.Txt.Text = Text
        end
    end
end

Announcement("Hello, this is an announcement")
0
so hard =/ j1011 0 — 8y
0
It really isn't - I've literally given you a function you could throw in. You'd just have to replace the text changing lines with Announcement(Text_Here)... DataStore 530 — 8y
Ad

Answer this question