#someone help me please

29 messages · Page 1 of 1 (latest)

charred fiber
#

Hello

cinder timber
charred fiber
#

first off, I wouldn't suggest to reconnect and disconnect the function each time it isn't necessary, instead you can use a variable inside the object to define whether the function can run or not, here's the fixed code aswell with a slight fix to prevent errors:

local endrace = script.Parent
local winsign = game.Workspace.WinnerSign.OwnerName.WinnerGUI.Winner
local players = game:GetService("Players")

endrace:SetAttribute("HasWinner")

local function raceWon(object)
    if endrace:GetAttribute("HasWinner") == true then return end --// RETURN IF EXECUTION WENT SUCCESSFUL
    
    local winner = players:GetPlayerFromCharacter(object.Parent)
    if not winner then return end -- // IF CANT GET PLAYER FROM CHARACTER THEN DONT RUN THE CODE (PREVENT ERROR)
    winner.PlayerGui.WinnerGui.Enabled = true
    winner.PlayerGui.WinnerGui.Winner.Text = object.Parent.Name
    endrace:SetAttribute("HasWinner",true) -- // SET TO TRUE TO PREVENT ANOTHER EXECUTION
    
    print("The Winner Is ", object.Parent.Name)
    winsign.Text = object.Parent.Name
    task.wait(5)
    winsign.Text = "Winner Is..."    



    task.wait(1)
    winner.PlayerGui.WinnerGui.Enabled = false
    for _, player in ipairs(players:GetPlayers()) do
        local character = player.Character
        if character then
            character:Destroy()
        end
        player:LoadCharacter()
    end
    --// IF YOU WANT TO RE ENABLE THAT FUNCTION TO WORK SET HasWinner TO FALSE
    endrace:SetAttribute("HasWinner",false)
end

endrace.Touched:Connect(raceWon)
cinder timber
#

dude tysm man it worked

charred fiber
#

no problem dude, I suggest you sometimes try to research solutions to these type of issues also with AI if you cant find anything online it can help you a lot but don't trust it too much just use it for tips n stuff like that, have a nice day

cinder timber
charred fiber
#

sure go for it

cinder timber
#

ive been trying to research how to highlight the winner of the race but i cant figure out how to do it because the script only knows the name of the player not the character

#

is there any way to do that?

charred fiber
#
local CHAR_TO_HIGHLIGHT = game.workspace:FindFirstChild(player.Name)
if CHAR_TO_HIGHLIGHT and CHAR_TO_HIGHLIGHT:IsA("Model") and players:GetPlayerFromCharacter(CHAR_TO_HIGHLIGHT) then
-- HIGHLIGHT
end
cinder timber
#

would this make the winner be highlighted? i just need the winner to be and not everyone

#

sorry for the questions

charred fiber
#
local CHAR_TO_HIGHLIGHT = game.workspace:FindFirstChild(player.Name)
if CHAR_TO_HIGHLIGHT and CHAR_TO_HIGHLIGHT:IsA("Model") and players:GetPlayerFromCharacter(CHAR_TO_HIGHLIGHT) then
local h = instance.new("Highlight",CHAR_TO_HIGHLIGHT)
h.Adornee = CHAR_TO_HIGHLIGHT
h.Enabled = true
end
#

when you want to remove it just findfirstchild highlight and destroy

#

:)

cinder timber
#

okay thank you man one more thing would i put this in the function?

charred fiber
#

ye you can

cinder timber
#

okay man tysm i put it right here ```local endrace = script.Parent
local winsign = game.Workspace.WinnerSign.OwnerName.WinnerGUI.Winner
local players = game:GetService("Players")

endrace:SetAttribute("HasWinner")

local function raceWon(object)
if endrace:GetAttribute("HasWinner") == true then return end --// RETURN IF EXECUTION WENT SUCCESSFUL
local CHAR_TO_HIGHLIGHT = game.workspace:FindFirstChild(players.Name)
if CHAR_TO_HIGHLIGHT and CHAR_TO_HIGHLIGHT:IsA("Model") and players:GetPlayerFromCharacter(CHAR_TO_HIGHLIGHT) then
local h = instance.new("Highlight",CHAR_TO_HIGHLIGHT)
h.Adornee = CHAR_TO_HIGHLIGHT
h.Enabled = true
end

local winner = players:GetPlayerFromCharacter(object.Parent)
if not winner then return end -- // IF CANT GET PLAYER FROM CHARACTER THEN DONT RUN THE CODE (PREVENT ERROR)
winner.PlayerGui.WinnerGui.Enabled = true
winner.PlayerGui.WinnerGui.Winner.Text = object.Parent.Name
endrace:SetAttribute("HasWinner",true) -- // SET TO TRUE TO PREVENT ANOTHER EXECUTION

print("The Winner Is ", object.Parent.Name)
winsign.Text = object.Parent.Name



task.wait(3)
winsign.Text = "Winner Is..."    

winner.PlayerGui.WinnerGui.Enabled = false
for _, player in ipairs(players:GetPlayers()) do
    local character = player.Character
    if character then
        character:Destroy()
    end
    player:LoadCharacter()
end
--// IF YOU WANT TO RE ENABLE THAT FUNCTION TO WORK SET HasWinner TO FALSE
endrace:SetAttribute("HasWinner",false)

end

endrace.Touched:Connect(raceWon)```

charred fiber
#
local endrace = script.Parent
local winsign = game.Workspace.WinnerSign.OwnerName.WinnerGUI.Winner
local players = game:GetService("Players")


endrace:SetAttribute("HasWinner")

local function raceWon(object)
    if endrace:GetAttribute("HasWinner") == true then return end --// RETURN IF EXECUTION WENT SUCCESSFUL
    local CHAR_TO_HIGHLIGHT = game.workspace:FindFirstChild(object.Parent.Name)
    if CHAR_TO_HIGHLIGHT and CHAR_TO_HIGHLIGHT:IsA("Model") and players:GetPlayerFromCharacter(CHAR_TO_HIGHLIGHT) then
        local h = instance.new("Highlight",CHAR_TO_HIGHLIGHT)
        h.Adornee = CHAR_TO_HIGHLIGHT
        h.Enabled = true
    end

    local winner = players:GetPlayerFromCharacter(object.Parent)
    if not winner then return end -- // IF CANT GET PLAYER FROM CHARACTER THEN DONT RUN THE CODE (PREVENT ERROR)
    winner.PlayerGui.WinnerGui.Enabled = true
    winner.PlayerGui.WinnerGui.Winner.Text = object.Parent.Name
    endrace:SetAttribute("HasWinner",true) -- // SET TO TRUE TO PREVENT ANOTHER EXECUTION

    print("The Winner Is ", object.Parent.Name)
    winsign.Text = object.Parent.Name
    


    task.wait(3)
    winsign.Text = "Winner Is..."    

    winner.PlayerGui.WinnerGui.Enabled = false
    for _, player in ipairs(players:GetPlayers()) do
        local character = player.Character
        if character then
            character:Destroy()
        end
        player:LoadCharacter()
    end
    --// IF YOU WANT TO RE ENABLE THAT FUNCTION TO WORK SET HasWinner TO FALSE
    endrace:SetAttribute("HasWinner",false)
end

endrace.Touched:Connect(raceWon)
cinder timber
#

my fault ym fault but there seems to be an error on this line local h = instance.new("Highlight",CHAR_TO_HIGHLIGHT) and the consol error is this 22:18:30.680 Workspace.End.RaceEnd.Script:12: attempt to index nil with 'new' - Server - Script:12

charred fiber
#
local endrace = script.Parent
local winsign = game.Workspace.WinnerSign.OwnerName.WinnerGUI.Winner
local players = game:GetService("Players")


endrace:SetAttribute("HasWinner")

local function raceWon(object)
    if endrace:GetAttribute("HasWinner") == true then return end --// RETURN IF EXECUTION WENT SUCCESSFUL
    local CHAR_TO_HIGHLIGHT = game.workspace:FindFirstChild(object.Parent.Name)
    if CHAR_TO_HIGHLIGHT and CHAR_TO_HIGHLIGHT:IsA("Model") and players:GetPlayerFromCharacter(CHAR_TO_HIGHLIGHT) then
        local h = Instance.new("Highlight",CHAR_TO_HIGHLIGHT)
        h.Adornee = CHAR_TO_HIGHLIGHT
        h.Enabled = true
    end

    local winner = players:GetPlayerFromCharacter(object.Parent)
    if not winner then return end -- // IF CANT GET PLAYER FROM CHARACTER THEN DONT RUN THE CODE (PREVENT ERROR)
    winner.PlayerGui.WinnerGui.Enabled = true
    winner.PlayerGui.WinnerGui.Winner.Text = object.Parent.Name
    endrace:SetAttribute("HasWinner",true) -- // SET TO TRUE TO PREVENT ANOTHER EXECUTION

    print("The Winner Is ", object.Parent.Name)
    winsign.Text = object.Parent.Name



    task.wait(3)
    winsign.Text = "Winner Is..."    

    winner.PlayerGui.WinnerGui.Enabled = false
    for _, player in ipairs(players:GetPlayers()) do
        local character = player.Character
        if character then
            character:Destroy()
        end
        player:LoadCharacter()
    end
    --// IF YOU WANT TO RE ENABLE THAT FUNCTION TO WORK SET HasWinner TO FALSE
    endrace:SetAttribute("HasWinner",false)
end

endrace.Touched:Connect(raceWon)
cinder timber
#

YOOO

#

IT WORKS

#

man tysm

charred fiber
#

np dude

cinder timber
#

hey @charred fiber i was wondering how i would make it so that there is a spawnarea and the players can vote on a race they wanna do and then they spawn at that race?

#

can u just give me a structure of it please>