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

Is there any other ways of making this AFK button work or how can I fix this ?

Asked by 7 years ago

I have already made everything and im not asking someone to just plain out give me the code but what ive tried is taking the humanoidrootpart away from the player and putting it in lighting right before the round starts and it still teleports the player to the map. I also tried putting a value inside a player to check if they have a vale of 1 which would mean they are AFK.

This is my games main script.

local repilcatedstorage = game.ReplicatedStorage
local status = game.ReplicatedStorage.InfoValue
local mapstorage = game.Workspace.mapStorage

while true do

while game.Players.NumPlayers < 2 do
 status.Value = 'There needs to be 2 or more players to begin'
 repeat wait(2) until game.Players.NumPlayers >= 2
end

for i = 90,0,-1 do
 status.Value = 'Intermission '..i
 wait(1) 
end

_G.gameplayers = {}
for i, v in pairs(game.Players:GetPlayers()) do

if v then
 table.insert(_G.gameplayers, v.Name)
end

end

local mapsinserverstorage = game.ServerStorage:GetChildren()
local chosenmap = mapsinserverstorage[math.random(1, #mapsinserverstorage)]
chosenmap:Clone().Parent = mapstorage
status.Value = 'Round Beginning!'
wait(3)
local spawns = chosenmap:WaitForChild('Spawns'):GetChildren()
for _, player in pairs (game.Players:GetPlayers()) do
    if player and #spawns > 0 then
        local torso = player.Character:WaitForChild('HumanoidRootPart')
        local allspawns = math.random(1, #spawns)
        local randomspawn = spawns[allspawns]
-- This right here is what I tried but still spawned the player into the map.
if game.Players.LocalPlayer.AFK.Value == 1 then
    local torso = game.Players.LocalPlayer.Character:WaitForChild('HumanoidRootPart')
    torso.Parent = game.Lighting
    wait(1)
end


        if randomspawn  and torso then
            table.remove(spawns, allspawns)
        torso.CFrame = CFrame.new(randomspawn.Position + Vector3.new(0,2,0))
local gun = game.ReplicatedStorage.Handgun
local newgun = gun:clone()
newgun.Parent = player.Backpack

        end
    end
end

for i = 120, 0, -1 do
    if i == 0 then
        status.Value = 'Round over!'
        break
    end

    wait(1)
    if #_G.gameplayers == 1 then
        for i, v in pairs(_G.gameplayers) do
            if v ~= nil then
                status.Value = v..' is the winner!'
                game.Players[v].leaderstats.Points.Value = game.Players[v].leaderstats.Points.Value + 50
                --game.Players[v].leaderstats.Exp.Value = game.Players[v].leaderstats.Exp.Value + 50
                break
            end
        end
        break
    else 
        status.Value = i..' seconds remaining!'
    end
end
mapstorage:ClearAllChildren()
wait(5)
end
0
Most inefficient way to check if there is less than 2 players. hiimgoodpack 2009 — 7y
0
I'm not asking that am I ? If you don't have anything to say about my question please just don't comment. 1Messi3903 -5 — 7y

2 answers

Log in to vote
0
Answered by
natsaa 5
7 years ago

From the looks of your script, I don't see anything that teleports the player- so we're probably missing a bunch of stuff from other scripts that we'd need to correctly answer this. But I'll try to answer your question as best as possible.

Somewhere, you have a script that is teleporting players to the map when the game starts. If you move the player before that happens, it won't affect anything, the teleport will still go through. The only thing you can do here (as you said) is to have some sort of variable that you check to see if the player is afk. A number value with 0 for playing and 1 for afk would work perfectly fine, but wherever your script is teleporting players you need to make sure you have a check for that number value as well.

0
I have tried this but from my game script that teleports the people it is a normal script and I dont know hoe to check values inside a player from this type of script. 1Messi3903 -5 — 7y
0
You're going to have to put an actual valueObject on the player (not a variable within a script), and reference that instead. natsaa 5 — 7y
Ad
Log in to vote
0
Answered by
Viking359 161
7 years ago

Add a string value or something like that to the player. Have the afk button change that value to "afk" or "ak". When the round starts, have it check each players afk value to see if they are afk or not.

Answer this question