Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Change (Name) to (Player) for server messages?

I am making this role play game and whoever touches the part first the message pops up on the front. I want it to say the players name instead of the vehcles parts.

local m = Instance.new("Message")
local h = Instance.new("Hint")
value = script.Parent.Value
function onTouch(hit)
value.Value = value.Value + 1
player = hit.Parent.Name
m.Parent = game.Workspace
m.Text = ""..Name.." has won the race!" --Change "has won the quiz" to whatever you want!
wait(3)
m:remove()
h.Parent = game.Workspace
h.Text = "The race has been won "..value.Value.." times!" --Do the same with "The quiz has been won"
wait(4)
h:remove()
end

script.Parent.Touched:connect(onTouch) 

I want the players name to be said. Not the part.

1 comment

0

remove() is deprecated, user Destroy() instead.

1 answer

-- Index the Object if you want to change it 
	-- Index the Value Property if you want to read from it
local WinsNumberValue = script.Parent.Value
-- So we can stop the win function once someone wins
local RaceActive = true
-- So we do not spam the function
local Debounce = true

local Hint = Instance.new("Hint")

local function ResetRace(Winner)
	-- find some way to re-activate the race; this is one way.
	Hint.Text = ('%s won the race!'):format(Winner.Name)
	Hint.Parent = workspace
	wait(3)
	for i = 5, 0, -1 do 
		Hint.Text = ('The game race has been won %s times; racing again in %d'):format(WinsNumberValue.Value, i)
		wait(1)
	end
	Hint.Parent = nil
	RaceActive = true
end

script.Parent.Touched:Connect(function(hit)
	if RaceActive and Debounce then 
		Debounce = false
		if hit and hit.Parent then
			-- Get Player from Character model
			local PlayerFromPart = game.Players:GetPlayerFromCharacter(hit.Parent)
			-- Is Character nil?
			local Character = PlayerFromPart and PlayerFromPart.Character 
			-- Is Humanoid nil?
			local Humanoid = Character and Character:FindFirstChild("Humanoid")
			-- if Humanoid and not Dead
			if Humanoid and Humanoid.Health > 0 then
				-- Disable the race
				RaceActive = false
				-- Add to wins
				WinsNumberValue.Value = WinsNumberValue.Value + 1
				-- Reset race function
				ResetRace(PlayerFromPart)
			end
		end 
		Debounce = true
	end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.