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)