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

Script checks if player is on red team then gives the player one point (check more text . -?)

Asked by 1 year ago
Edited 1 year ago

How do I make it so after gives 1 point it makes a frame visible then kills all players in the server then makes frame not visible. I am trying to make it so when a player scores a point when he touches the part if makes a frame visible( game.StarterGui.RedTeamScored.Frame) then after like 1 second it kills all players and makes the frame not visible.

`local Players = game:GetService("Players")

local Teams = game:GetService("Teams")

local debounce = false

script.Parent.Touched:Connect(function(hit)
    local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
    if player and player.Team == Teams["Red Team"] then
        if debounce then return end
        debounce = true
        player.leaderstats.Points.Value += 1
        task.wait(3)
        debounce = false
    end
end)`
0
Can you be a bit more clear? What exactly are you trying to do? BoiBoi24T 63 — 1y
0
I edited post BoiBoi24T MariamOMG090 9 — 1y

2 answers

Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

Instead of using the StarterGui to make the frame visible, you should use the PlayerGui inside the Player, since everything inside StarterGui will replicate inside Player.PlayerGui when the player joins. Another reason is that if you tried to edit it in StarterGui, it won't affect PlayerGui, and StarterGui is only accessible in the client (LocalScripts).

To kill every player in the server, you can get an array of all players in the server using Players:GetPlayers() and iterate through the array using either pairs() or ipairs(). ipairs() is recommended for arrays because it is faster. To kill the player, you can use either Player:LoadCharacter() or Player.Character:FindFirstChildOfClass("Humanoid").Health = 0. The difference between the two is their RespawnTime. Player:LoadCharacter() respawns the player immediately, while Player.Character:FindFirstChildOfClass("Humanoid").Health = 0 respawns after 3 seconds (default).

Final Script:

local Players = game:GetService("Players")
local Teams = game:GetService("Teams")

local function killEveryPlayer()
    for _, player in ipairs(Players:GetPlayers()) do
        task.spawn(function()
            local character = player.Character
            if (not character) or (not character.Parent) then
                character = player.CharacterAdded:Wait()
            end
            character:FindFirstChildOfClass("Humanoid").Health = 0
        end)
    end
end

local function redTeamScoredFrame(visible: boolean)
    for _, player in ipairs(Players:GetPlayers()) do
        task.spawn(function()
            player:WaitForChild("PlayerGui"):WaitForChild("RedTeamScored"):WaitForChild("Frame").Visible = visible
            player:WaitForChild("PlayerGui"):WaitForChild("DeathGui").Enabled = not visible
        end)
    end
end

local debounce = false
script.Parent.Touched:Connect(function(hit)
    local player = Players:GetPlayerFromCharacter(hit:FindFirstAncestorOfClass("Model"))
    if (player and player.Team.Name == "Red Team") and (debounce == false) then
        debounce = true
        player.leaderstats.Points.Value += 1

        task.spawn(killEveryPlayer)
        task.spawn(redTeamScoredFrame, true) -- makes RedTeamScore Frame visible

        task.wait(3)
        task.spawn(redTeamScoredFrame, false) -- makes RedTeamScore Frame invisible
        debounce = false
    end
end)
0
@T3_MasterGamer it gives me an error at: 'task.spawn(redTeamScored, true)' and 'task.spawn(redTeamScored, true)' it puts a red line under both redTeamScored MariamOMG090 9 — 1y
0
It gives me the error: Workspace.BlueSide.Void.BlueScript:32: invalid argument #1 to 'spawn' (function or thread expected) MariamOMG090 9 — 1y
0
Oh sorry! I fixed it. T3_MasterGamer 2189 — 1y
0
It still does not work but it does not give me an error this time. Do i have to put the Frame somewhere besides starterGui? MariamOMG090 9 — 1y
View all comments (10 more)
0
Is the script a normal scritp and inside ServerScriptService? T3_MasterGamer 2189 — 1y
0
Nevermind I fixed it, But I have one last thing to ask you. So I have a Respawning Gui that comes up when you die and tells you how many secs till respawn. So my question is, How do I make it so when the player scores it shows the redTeamScored Gui but not the respawning Gui.(respawning gui: game.StarterGui.DeathGui) MariamOMG090 9 — 1y
0
Do you have a script that popups the DeathGui? T3_MasterGamer 2189 — 1y
0
Yes MariamOMG090 9 — 1y
0
Show me. T3_MasterGamer 2189 — 1y
0
Check Answers place MariamOMG090 9 — 1y
0
Done! Please accept my answer if it works. :) T3_MasterGamer 2189 — 1y
0
It does not work, it does not give me any errors for this script but it gives me an error in the script thats in DeathGui. This is the error: Players.PreviousSchmuck.PlayerGui.DeathGui.LocalScript:10: attempt to index nil with 'Value' MariamOMG090 9 — 1y
0
Change line 10 of the local script in deathgui to `if killer and killer.Value then` you should always check if the creator tag exists, if not it will error if player resets on themself. T3_MasterGamer 2189 — 1y
0
It does not work, Now it just shows the DeathGui and the redTeamScored Gui does not show. MariamOMG090 9 — 1y
Ad
Log in to vote
0
Answered by 1 year ago

to T3_MasterGamer's comment:

This first script is in the DeathGui:

local cam = workspace.CurrentCamera
local plr = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local imalabel = script.Parent.Frame.ImageLabel
local texlabel = script.Parent.Frame.TextLabel

hum.Died:Connect(function(killed)
    local killer = char.Humanoid:FindFirstChild("creator")
    if killer.Value then

        local killerChar = killer.Value.Character
        local killerName = killer.Value.Name
        local killerId = killer.Value.UserId
        local image, isReady = game.Players:GetUserThumbnailAsync(killerId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size180x180)

        cam.CameraSubject = killerChar.Humanoid
        script.Parent.Frame.Visible = true
        imalabel.Image = image
        texlabel.Text = killerName
        wait(10)
        cam.CameraSubject = hum
        script.Parent.Frame.Visible = false

    end
end)

This script is in ServerScriptService:

local players = game.Players
local t = 5

players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        local humanoid = character:WaitForChild("Humanoid")

        humanoid.Died:Connect(function(died)
            player.PlayerGui:FindFirstChild("DeathGui"):WaitForChild("Frame").Visible = true

            for i = t,0,-1 do
                player.PlayerGui:FindFirstChild("DeathGui").Frame.Timer.Text = "Respawning in"..i
                wait(1)
            end
            player.PlayerGui:FindFirstChild("DeathGui"):WaitForChild("Frame").Visible = false
        end)
    end)
end)

Answer this question