I'm trying to make a part that if you step on it gives you a win and then teleports you to the start. The thing is it would give you 2 or 3 wins if you touched it. So this is my solution, and I'm having problems. Anybody know what's wrong?

WinScript, game.Workspace.WinPart.WinScript(server script)

local WinPart = script.Parent

WinPart.Touched:Connect(function(hit)	
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	
	local BoolVal = player.BoolVal
	
	if player then
		
		if BoolVal.Value == true then
			
			local leaderstats = player:FindFirstChild("leaderstats")
			
			if leaderstats then
				
					local Player = game.Players.LocalPlayer
					
					local Location = game.Workspace.TeleportLocation
					local RepStore = game:GetService("ReplicatedStorage")
					local WinValue = game.ReplicatedStorage.WinValue
					
					local clone = WinValue
					clone.Parent = Player
					clone.Name = WinValue
					
					WinValue.Value = true
					
					hit.Parent.HumanoidRootPart.CFrame =  CFrame.new(Location.Position)
					
					wait(1)
					
			end
		end
	end
end)

LocalWinGiver, game.StarterPlayer.StarterPlayerScripts.LocalWinGiver(local script)

local RepStore = game:GetService("ReplicatedStorage")
local WinValue = RepStore.WinValue

local player = game.Players.LocalPlayer

local PlayerWinVal = player.WinValue

WinValue.Value = false

while true do
	wait(1)
	if PlayerWinVal.Value == true then
		player.leaderstats.Wins.Value = player.leaderstats.Wins.Value + 1
		PlayerWinVal.Value = false
	end
	
end

2 comments

1

it's literally in english. win value isnt in the player

0

I'm pretty sure it's because the touched event is used in a server script, in which game.Players.LocalPlayer is used to find the VinValue, but LocalPlayer is only accessible by a LocalScript.