#someone help me please
29 messages · Page 1 of 1 (latest)
hi
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)
dude tysm man it worked
really appriciate you man
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
okay man i will i appriciate you, i also have a question rq if u dont mind
sure go for it
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?
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
would this make the winner be highlighted? i just need the winner to be and not everyone
sorry for the questions
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
:)
okay thank you man one more thing would i put this in the function?
ye you can
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)```
you need to change players.Name to object.Parent.Name
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)
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
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)
np dude