The script works 100% but when the victim of the minigame dies the minigame doesn’t reset even thought I scripted it to
Code:
local Players = game.Players:GetPlayers()
local Sounds = script:WaitForChild("Playtime Sounds")
local HitBox = script.Parent
local Playtimegui = game.StarterGui:WaitForChild("Playtime ui")
local Rope = Playtimegui:WaitForChild("Rope")
local minigameprogress = script:WaitForChild("minigameprogress")
local minigameprogresstext = Playtimegui.Frame:WaitForChild("minigameprogress")
local contentloader = game:GetService("ContentProvider")
local isplaytimeavailable = true
local Minigamecompleted = false
Sounds["Playtime's Theme"]:Play()
Ropeassets = {
"rbxassetid://17309020766",
"rbxassetid://17309020583",
"rbxassetid://17309020358",
"rbxassetid://17309020210",
"rbxassetid://17309020023"
}
Playtimesoundsassets = {
"rbxassetid://17311954085",
"rbxassetid://17311953908",
"rbxassetid://17311953569",
"rbxassetid://17311953180",
"rbxassetid://17311953378"
}
contentloader:PreloadAsync(Ropeassets)
contentloader:PreloadAsync(Playtimesoundsassets)
HitBox.Touched:Connect(function(part)
local plr = game:GetService("Players"):GetPlayerFromCharacter(part.Parent)
if plr then
if plr:FindFirstChild("Student") and plr:FindFirstChild("isplaying") then
if plr.isplaying.Value == false then
plr.isplaying.Value = true
isplaytimeavailable = false
wait(0.2)
plr.Character.Humanoid.WalkSpeed = 0
plr.Character.Humanoid.JumpPower = 40
Sounds["Playtime ready go!"]:Play()
plr.PlayerGui["Playtime ui"].Enabled = true
Sounds["Playtime ready go!"]:Play()
wait(Sounds["Playtime ready go!"].TimeLength)
minigame(plr)
end
else
print("Player either doesn't have Student or is alreaady playing with playtime!")
end
end
end)
function minigame(plr)
repeat
if plr.Character and plr.Student then
repeat
plr.PlayerGui["Playtime ui"].Frame.minigameprogress.Text = "0"
plr.PlayerGui["Playtime ui"].Rope.Image = "rbxassetid://17309020766"
wait(0.3)
plr.PlayerGui["Playtime ui"].Rope.Image = "rbxassetid://17309020583"
wait(0.3)
plr.PlayerGui["Playtime ui"].Rope.Image = "rbxassetid://17309020358"
wait(0.3)
plr.PlayerGui["Playtime ui"].Rope.Image = "rbxassetid://17309020210"
wait(0.3)
plr.PlayerGui["Playtime ui"].Rope.Image = "rbxassetid://17309020023"
wait(0.3)
plr.PlayerGui["Playtime ui"].Rope.Image = ""
if plr.Character.Humanoid:GetState() == Enum.HumanoidStateType.Jumping or plr.Character.Humanoid:GetState() == Enum.HumanoidStateType.Freefall then
if minigameprogress == 0 then
Sounds["Playtime 1"]:Play()
minigameprogress = minigameprogress + 1
plr.PlayerGui["Playtime ui"].Frame.minigameprogress.Text = "1"
elseif minigameprogress == 1 then
Sounds["Playtime 2"]:Play()
minigameprogress = minigameprogress + 1
plr.PlayerGui["Playtime ui"].Frame.minigameprogress.Text = "2"
elseif minigameprogress == 2 then
minigameprogress = minigameprogress + 1
Sounds["Playtime 3"]:Play()
plr.PlayerGui["Playtime ui"].Frame.minigameprogress.Text = "3"
elseif minigameprogress == 3 then
minigameprogress = minigameprogress + 1
Sounds["Playtime 4"]:Play()
plr.PlayerGui["Playtime ui"].Frame.minigameprogress.Text = "4"
elseif minigameprogress == 4 then
minigameprogress = minigameprogress + 1
Sounds["Playtime 5"]:Play()
plr.PlayerGui["Playtime ui"].Frame.minigameprogress.Text = "5"
Minigamecompleted = true
plr.isplaying.Value = false
plr.PlayerGui["Playtime ui"].Enabled = false
plr.PlayerGui["Playtime ui"].Frame.minigameprogress.Text = "0"
end
else
minigameprogress = 0
plr.PlayerGui["Playtime ui"].Frame.minigameprogress.Text = "0"
Sounds["Playtime oops!"]:Play()
wait(Sounds["Playtime oops!"].TimeLength)
end
until Minigamecompleted == true
elseif plr.Character and not plr.Student then
plr.PlayerGui["Playtime ui"].Enabled = false
minigameprogress = 0
plr.PlayerGui["Playtime ui"].Rope.Image = ""
Minigamecompleted = false
plr.isplaying.Value = false
wait(3)
break
end
until plr.isplaying.Value == false
wait(3)
minigameprogress = 0
Minigamecompleted = false
isplaytimeavailable = true
end
Also at line 41 when the player walkspeed is supposed to be set to 0 it doesn’t set
Also more than 1 player can play the minigame even though it is supposed to be one at a time
I can’t put it in serverscriptservice because the way I wrote it it needs to be in the charactor of the person who forces the player to do the minigame
this is just a rework of the basic script to make it more neat and will give you errors. please follow some of these tips so its actually readable. and functionable
local Players = game.Players:GetPlayers()
local Sounds = script:WaitForChild("Playtime Sounds")
local HitBox = script.Parent
local Playtimegui = game.StarterGui:WaitForChild("Playtime ui")
local Rope = Playtimegui:WaitForChild("Rope")
local minigameprogress = script:WaitForChild("minigameprogress")
local minigameprogresstext = Playtimegui.Frame:WaitForChild("minigameprogress")
local contentloader = game:GetService("ContentProvider")
local isplaytimeavailable = true
local Minigamecompleted = false
Sounds["Playtime's Theme"]:Play()
Ropeassets = {
"rbxassetid://17309020766",
"rbxassetid://17309020583",
"rbxassetid://17309020358",
"rbxassetid://17309020210",
"rbxassetid://17309020023"
}
Playtimesoundsassets = {
"rbxassetid://17311954085",
"rbxassetid://17311953908",
"rbxassetid://17311953569",
"rbxassetid://17311953180",
"rbxassetid://17311953378"
}
contentloader:PreloadAsync(Ropeassets)
contentloader:PreloadAsync(Playtimesoundsassets)
--Use guard statments like if not return end its easier to read
HitBox.Touched:Connect(function(part)
local plr = game:GetService("Players"):GetPlayerFromCharacter(part.Parent)
if not plr then return end
--Check for character and humanoid
local Character = plr.Character or plr.CharacterAdded:Wait()
if not Character then warn("No character found") return end
if not Character:WaitForChild("Humanoid") then warn("No humanoid found") return end
if not plr:FindFirstChild("Student") then warn("Student not found") return end
if not plr:FindFirstChild("isplaying") then warn("isplaying not found") return end
if not plr.isplaying.Value then -- debounce isnt a guard clause
plr.isplaying.Value = true
isplaytimeavailable = false
--use task.wait instead of wait
task.wait(0.2)
Character.Humanoid.WalkSpeed = 0
Character.Humanoid.JumpPower = 40
Sounds["Playtime ready go!"]:Play()
--check for playergui
if plr:WaitForChild("PlayerGui") then
plr.PlayerGui["Playtime ui"].Enabled = true
end
Sounds["Playtime ready go!"]:Play()
task.wait(Sounds["Playtime ready go!"].TimeLength)
minigame(plr)
end
end)
function minigame(plr)
--repeat statements inside one another is a terrible idea so laggy
--try to find another way if possible in coding generally you wanna avoid loops
repeat
if plr.Character and plr.Student then
repeat
--Make funcs so you dont repeat code
local function UpdateRopeImage(Image:string,DoText:boolean)
if DoText then
-- should use waitforchild to make sure frame and minigame progress load
--but im too lazy
plr.PlayerGui["Playtime ui"].Frame.minigameprogress.Text = "0"
end
plr.PlayerGui["Playtime ui"].Rope.Image = Image
task.wait(0.3)
end
UpdateRopeImage("rbxassetid://17309020766",true)
UpdateRopeImage("rbxassetid://17309020583")
UpdateRopeImage("rbxassetid://17309020358")
UpdateRopeImage("rbxassetid://17309020210")
UpdateRopeImage("rbxassetid://17309020023")
UpdateRopeImage("")
if plr.Character.Humanoid:GetState() == Enum.HumanoidStateType.Jumping
or plr.Character.Humanoid:GetState() == Enum.HumanoidStateType.Freefall
then
minigameprogress.Value += 1
Sounds["Playtime"..tostring(minigameprogress.Value)]:Play()
plr.PlayerGui["Playtime ui"].Frame.minigameprogress.Text = tostring(minigameprogress.Value )
if minigameprogress.Value == 4 then
Minigamecompleted = true
plr.isplaying.Value = false
plr.PlayerGui["Playtime ui"].Enabled = false
plr.PlayerGui["Playtime ui"].Frame.minigameprogress.Text = "0"
end
else
minigameprogress.Value = 0
plr.PlayerGui["Playtime ui"].Frame.minigameprogress.Text = "0"
Sounds["Playtime oops!"]:Play()
wait(Sounds["Playtime oops!"].TimeLength)
end
until Minigamecompleted
elseif plr.Character and not plr.Student then
plr.PlayerGui["Playtime ui"].Enabled = false
minigameprogress.Value = 0
plr.PlayerGui["Playtime ui"].Rope.Image = ""
Minigamecompleted = false
plr.isplaying.Value = false
task.wait(3)
break
end
until not plr.isplaying.Value
task.wait(3)
minigameprogress.Value = 0
Minigamecompleted = false
isplaytimeavailable = true
end
i dont even see a part where u coded in if they die?
also this should be a server script theres always another way to code something. the way this is being coded in itself is a bad system. dont use loops use events, dont repeat urself use functions.
if i better understood what it was you’re trying to achieve id show you how id go about doing it.
if you’re trying to find if someone died use
its likely that the player dies and the character variable for the new character isnt being updated so it will say that character = nil because you dont reset the variable when a new character is added which you can use character.added:wait()
Humanoid.Died:Connect(function()
--Humanoid died :p
end)
it would REALLY do you some good to learn about events how to use them, how to disconnect them etc
You were right about the it will give you errors part it gave me a error
Workspace.Unfinished_Playtime.Hitbox.PlaytimeScript:94: attempt to perform arithmetic (add) on Instance and number - Server - PlaytimeScript:94
14:35:04.533 Stack Begin - Studio
14:35:04.534 Script ‘Workspace.Unfinished_Playtime.Hitbox.PlaytimeScript’, Line 94 - function minigame - Studio - PlaytimeScript:94
14:35:04.534 Script ‘Workspace.Unfinished_Playtime.Hitbox.PlaytimeScript’, Line 62 - Studio - PlaytimeScript:62
14:35:04.535 Stack End - Studio
I am new to scripting so my code will mostly be messy I will try to learn about events and functions because I know I need to use them to add custom gamemodes to my game, I also try to learn stuff about CollectionService to not repeat myself
The problems with the original script was that 1. 2 or more players could play the minigame even though it was supposed to be only one 2. if the player dies while playing the minigame it doesn’t reset and keeps going 3. the progress counter didn’t update 4. at line 41 of the original script where the player walkspeed was supposed to be at 0 it doesn’t update and thats all
local minigameprogress = script:WaitForChild("minigameprogress")
-- this is an instance NOT a number
if minigameprogress == 0 then -- checking if its a number but its not
Sounds["Playtime 1"]:Play()
minigameprogress = minigameprogress + 1 -- wont add 1 because its not a number
plr.PlayerGui["Playtime ui"].Frame.minigameprogress.Text = "1"
elseif minigameprogress == 1 then -- checking if its a number but its not
Sounds["Playtime 2"]:Play()
minigameprogress = minigameprogress + 1 -- wont add 1 because its not a number
plr.PlayerGui["Playtime ui"].Frame.minigameprogress.Text = "2" not
elseif minigameprogress == 2 then -- checking if its a number but its
etc...
Playtime1 is not a valid member of Folder “Workspace.Unfinished_Playtime.Hitbox.PlaytimeScript.Playtime Sounds” - Server - PlaytimeScript:95
14:57:22.614 Stack Begin - Studio
14:57:22.616 Script ‘Workspace.Unfinished_Playtime.Hitbox.PlaytimeScript’, Line 95 - function minigame - Studio - PlaytimeScript:95
14:57:22.616 Script ‘Workspace.Unfinished_Playtime.Hitbox.PlaytimeScript’, Line 62 - Studio - PlaytimeScript:62
14:57:22.617 Stack End - Studio
I fixed the error myself however the main problem is still here if the player whos playing the minigame dies the minigame still doesn’t reset thats like the only reason I’m not releasing the character right now