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

(AlvinBlox tut) Why doesn't player1 killed player2 appear in the status bar?

Asked by 2 years ago

So I have recently moved on from web development to try and learn roblox scripting since it is a lot easier (and less costly!) to publish my works. I also wanted to work with a game engine for once and C# in unity is much harder to learn than lua. I've watched all of AlvinBlox's beginner and advanced tuts on lua and have now moved on to this (https://www.youtube.com/watch?v=YODOWwLZaxE&list=PLsbxI7NIoTthI4KAXPMls60gwVkJbDEl1&index=3) video series to learn how to combine all of this lua knowledge and make a game out of it. Everything was going fine except for one thing which only started after this video.

The problem is that it should pop up in the TextLabel that player1 killed player2 everytime someone kills someone else but it doesn't. Another error I noticed was that the string "(mapname) was Chosen!" doesn't pop up in the TextLabel before "Game Starting..."

There are no errors and I have saved my scripts and also checked over them, analysing them against AlvinBlox's video and also other people that had different problems and posted their script. Here are the two scripts.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local MapsFolder = ServerStorage:WaitForChild("Maps")
local Status = ReplicatedStorage:WaitForChild("Status")
local GameLength = 50
local reward = 100

while true do
    -- intermission / waiting for players
    Status.Value = "Waiting for players..."
    repeat wait(1) until game.Players.NumPlayers >= 2
    Status.Value = "Intermission"
    wait(10)

    -- add each player to a table
    local plrs = {}
    for i, player in pairs(game.Players:GetPlayers()) do
        if player then
            table.insert(plrs,player)
        end
    end
    wait(2)

    -- randomly choose map
    local AvailableMaps = MapsFolder:GetChildren()
    local ChosenMap = AvailableMaps[math.random(1,#AvailableMaps)]
    Status.Value = ChosenMap.Name.." has been Chosen!"
    local ClonedMap = ChosenMap:Clone()
    ClonedMap.Parent = workspace

    -- spawn players in map
    local SpawnPoints = ClonedMap:FindFirstChild("SpawnPoints")
    if not SpawnPoints then
        print("SpawnPoints not found")
    end
    local AvailableSpawnPoints = SpawnPoints:GetChildren()
    for i, player in pairs(plrs) do
        if player then
            character = player.Character
            if character then
                -- teleport player
                character:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[1].CFrame
                table.remove(AvailableSpawnPoints,1)

                -- give sword
                local Sword = ServerStorage.Sword:Clone()
                Sword.Parent = player.Backpack

                -- give gametag
                local GameTag = Instance.new("BoolValue")
                GameTag.Name = "GameTag"
                GameTag.Parent = player.Character
            else
                if not player then
                    table.remove(plrs,i)
                end
            end
        end
    end

    -- start game
    Status.Value = "Game Starting..."
    wait(2)
    for i = GameLength,0,-1 do
        for x, player in pairs(plrs) do
            if player then
                character = player.Character
                if not character then
                    -- ignore
                else
                    if character:FindFirstChild("GameTag") then
                        print(player.Name.." is still in the game")
                    else
                        table.remove(plrs,x)
                        print(player.Name.." has been removed")
                    end
                end
            else
                table.remove(plrs,x)
                print(player.Name.." has been removed")
            end
        end
        Status.Value = "There are "..i.." seconds remaining, and "..#plrs.." players left"
        if #plrs == 1 then
            Status.Value = plrs[1].Name.." Won!"
            plrs[1].leaderstats.Cash.Value = plrs[1].leaderstats.Cash.Value + reward
            break
        elseif #plrs == 0 then
            Status.Value = "Nobody Won"
            break
        elseif i == 0 then
            Status.Value = "Time up"
            break
        end
        wait(1)
    end
    print("End of Game")
    for i, player in pairs(game.Players:GetPlayers()) do
        character = player.Character
        if not character then
            -- ignore
        else
            if character:FindFirstChild("GameTag") then
                character.GameTag:Destroy()
            end
            if player.Backpack:FindFirstChild("Sword") then
                player.Backpack.Sword:Destroy()
            end
            if character:FindFirstChild("Sword") then
                character.Sword:Destroy()
            end
        end
        player:LoadCharacter()
    end
    ClonedMap:Destroy()
    Status.Value = "Game Ended"
    wait(2)
end

^^^ this is the MainScript that controls the game

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local cash = Instance.new("IntValue")
    cash.Name = "Cash"
    cash.Value = 0
    cash.Parent = leaderstats

    player.CharacterAdded:Connect(function(character)

        character.Humanoid.Died:Connect(function()

            if character.Humanoid and character.Humanoid:FindFirstChild("creator") then
                game.ReplicatedStorage.Status.Value = tostring(character.Humanoid.creator.Value).." KILLED "..player.Name
            end
            if character:FindFirstChild("GameTag") then
                character.GameTag:Destroy()
            end

            player:LoadCharacter()
        end)
    end)
end)

^^^ and this is the Stats script that controls the leaderboard, player cash, etc

I understand that AlvinBlox apparently makes bad tutorials with outdated and bad code but I am not the type of person to just leave hours of work behind and give up on something since I was planning on modifying the code with actual animations and different swords to make a Combat Warriors style game

0
Oh and also, the "player1 won!" string should show up after the second last player dies but instead it shows up after the second last player respawns which isn't what is supposed to happen Buzz_ClipZz 0 — 2y
0
go to unity, roblox is for developers that barely earn anything, we are poor losers greatneil80 2647 — 2y
0
yea ive used unity and made a few games in it but C# is a lot harder to learn and roblox seems to be a lot simpler than unity. i dont really care about money, i am only 15 and have a job. im just doing this so i can practice debugging with an easy lang since i want to go to uni for a computer science course so may as well start now Buzz_ClipZz 0 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

I ended up not being able to find a solution for my problem so instead I resorted to just making an entirely new text label for a killfeed and modified some scripts and it is even better than before. I think the problem was just that I was trying to modify the same value with different values at the same time so they clashed. This code was directly from AlvinBlox though so I'd say that he just needs to improve his code.

Ad

Answer this question