Mini game Script

For my minigame script, I want to make it so that when the humanoid touches the part CanCollide will be false and it spits out the name of the player who won. When I try to do this, the game is fine in studio but when I go to the game it’s completely broken.

Here’s the way it works in studio:

https://gyazo.com/2976a9797981bcbd7c0d7e57f0a80986

And here’s the way it works in-game:

https://gyazo.com/a4129b9fbbb6830b0565889eb5167ef2

local s= script.Stat --the s meaning Stat
local vals = game.ReplicatedStorage.vals
 t=0
while true do
	t = 15
	repeat
		t = t-1
		s.Value = "Intermission.. "..t
		wait(1)
	until t == 0
	s.Value = "Game Starting!"
	wait(2)
	local mapselect = game.ReplicatedStorage.Games:GetChildren()
	local choose = math.random(1,#mapselect)
	curnum = 0
	for i =1, #mapselect do
		curnum = curnum +1
		if curnum == choose then
			mapselect[i]:Clone().Parent = workspace
			curmap = mapselect[i].Name
			s.Value = "We'll be playing "..mapselect [i].Name
		end
	end
	wait(3)
	local plrs = game.Players:GetChildren()
	for i = 1, #plrs do
		local num = math.random(1,15)
		plrs[1].Character.Head.CFrame= CFrame.new (workspace.Teleports["Part"..num].Position)
		plrs[i].Character.Parent = workspace.Ingame
	end
	t=100
	repeat
		t = t-1
		s.Value = t.." seconds left"
		wait(1)
	until t==0 or vals.Winner.Value ~= ""
	if vals.Winner.Value ~= "" then
		s.Value = vals.Winner.Value.. " has won!"
		vals.Winner.Value = ""
	else
			s.Value = "No one has won!"		
	end
	wait(3)
	local ingame = workspace.Ingame:GetChildren()
	for i =1,#ingame do
		local plr = game.Players:GetPlayerFromCharacter(ingame[i])
		plr:LoadCharacter()
		workspace[curmap]:Destroy()
	end
end

And my code for my part that gets touched in the minigame:

script.Parent.Touched:Connect(function(hit)
	local h = hit.Parent:FindFirstChild ("Humanoid")
	if (h~=nil) then
		game.ReplicatedStorage.vals.Winner.Value = hit.Parent.Name 
		script.Parent:Destroy()
	end
end)
2 Likes

Hello!
The scripts seems okay… Are you using a server script for both cases? If you are, then add print checks in both scripts so we may figure out where’s the issue. You can view the output in-game by pressing F9.

As a side note, when you need to get a table with all the players you should call :GetPlayers() instead of :GetChildren().

Also, I believe you will be teleporting just 1 player with this command:

plrs[1].Character.Head.CFrame= CFrame.new (workspace.Teleports["Part"..num].Position)

I think you should index plrs[i] instead as you’ve done underneath.

Finally I recommend you to store maps inside ServerStorage instead of ReplicatedStorage since it is safer against exploiters.

2 Likes

Hey, now that I go into studio, the game doesn’t work at all. I edited the scripts and this is the output:
image
I don’t know how I can fix this so please explain in very simple turns because I’m a beginner when it comes to scripting. You can add me on discord if you would like. I would prefer to talk there because i’m very active there. UwUBaconly#3146
-Thanks.