How to check if a player has already touched a part

I’m making a winning system in which if the player touches the trophy at the end then they will win and then the time will speed up by an exponential amount, basically what TOH does when you reach the top

what it does currently is if the player keeps on touching the trophy the multiplier will just go up a bunch instead of 1 time and it doesn’t check if the player has already touched the trophy

here’s the script

local trophy = script.Parent.Touch -- the hit box basically 
local multiplier = game.ServerScriptService.RoundSystem.Multiplier

local function PlayerTouched(Part)
	local Parent = Part.Parent
	
	if game.Players:GetPlayerFromCharacter(Parent) then
		multiplier.Value = multiplier.Value * 2 -- speeds up the time by 2 every time a player has touched the trophy
	end
end
3 Likes
local touchedPlayers = {}

local trophy = script.Parent.Touch
local multiplier = game.ServerScriptService.RoundSystem.Multiplier

local function PlayerTouched(part)
    local player = game.Players:GetPlayerFromCharacter(par
2 Likes

Add a BoolValue to each player then change it to true when the player touches it.
Check in your PlayerTouched if the bool is true in the player that just touched it. If it’s true then don’t increase the multiplier.

1 Like

What @Scottifly said and maybe you could use …
player.Character:SetAttribute(“Trophy”, true)
player.Character:GetAttribute(“Trophy”)

To set and test with.

1 Like

would I put the bool in the starterGui or the starterPlayer or somewhere else?

1 Like

You could use a bool value if you want it to be like already touched forever per account use data stores if not then use a bool value.

local trophy = script.Parent.Touch -- the hit box basically 
local multiplier = game.ServerScriptService.RoundSystem.Multiplier

local function PlayerTouched(Part)
	local Parent = Part.Parent
	local plr = game.Players:GetPlayerFromCharacter(Parent)
if plr then
if plr.HasTouched.Value == false then
		multiplier.Value = multiplier.Value * 2 -- speeds up the time by 2 every time a player has touched the trophy
plr.HasTouched.Value = true
end
	end
end```
5 Likes

you can use a variable that will be set to true when the part is touched, and in the script check the value of the variable. if it is false then set it to true and do whatever else you want, if it is true then do nothing.

1 Like

how would I make it so every player has a bool value, would i have to put it in the PlayerGui or the StarterPlayer or somewhere else?

1 Like

that only works if there’s going to be only 1 winner but i want it so multiple people can win just like in TOH

1 Like

use a localscript, then place is in starterplayerscripts. that should make it so the variable only applys to the player that touched the part.

1 Like

Put this in server script service.

game.Players.PlayerAdded:Connect(function(plr)
local bool = Instance.new("BoolValue")
bool.Name = "HasTouched"
bool.Value = false
bool.Parent = plr
end)
1 Like

i had to change a tiny bit of code at the top cause the function wasn’t working but in the end, I got it to work, Thanks.

Brant

here’s the code if you want to know what i changed

local trophy = script.Parent.Touch
local multiplier = game.ServerScriptService.RoundSystem.Multiplier

trophy.Touched:Connect(function(Part)
	local Parent = Part.Parent
	local player = game.Players:GetPlayerFromCharacter(Parent)

	if player then
		if player.HasWon.Value == false then
			multiplier.Value = multiplier.Value * 2
			player.HasWon.Value = true
			print("player has won and changed value")
		end

	end
end)
4 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.