-- assume we are in the character, let's check


function sepuku()
	script.Parent = nil
end

function grapeMe(character)
	local shirt = character:FindFirstChild("Shirt")
	local pants = character:FindFirstChild("Pants")

	if (shirt ~= nil) then shirt:Remove() end
	if (pants ~= nil) then pants:Remove() end

	local c = character:GetChildren()
	for i=1,#c do
		if (c[i].className == "Part") then
			c[i].Material = Enum.Material.Ice
			c[i].BrickColor = BrickColor.new("Magenta")
		end
	end
end



function UpdateUI(timeleft)
	local player = game.Players:GetPlayerFromCharacter(script.Parent)
	player.PlayerGui.GrapeGUI.Frame.Frame.Time.Text = timeleft .. " seconds"

	if (timeleft < 10) then
		player.PlayerGui.GrapeGUI.Frame.Frame.Warning.TextColor = BrickColor.new("Really red")
		if (timeleft % 2 == 1) then
			player.PlayerGui.GrapeGUI.Frame.Frame.Warning.Text = "WARNING"
		else
			player.PlayerGui.GrapeGUI.Frame.Frame.Warning.Text = "Mindgrapes on FIRE!!!"
		end
	else
		player.PlayerGui.GrapeGUI.Frame.Frame.Warning.TextColor = BrickColor.new("Hot pink")
		player.PlayerGui.GrapeGUI.Frame.Frame.Warning.Text = "Mindgrapes Ok..."
	end
end

local h = script.Parent:FindFirstChild("Humanoid")

if (h == nil) then sepuku() end

local oldSpeed = h.WalkSpeed
h.WalkSpeed = h.WalkSpeed * 2

h.MaxHealth = h.MaxHealth * .25
if (h.Health > h.MaxHealth) then h.Health = h.MaxHealth end




local torso = script.Parent:FindFirstChild("Torso")

if (torso == nil) then sepuku() end


local head = script.Parent:FindFirstChild("Head")
if (head == nil) then head = torso end


local Hyper = Instance.new("Sound")
Hyper.SoundId = "http://www.roblox.com/asset/?id=16950418"
Hyper.Parent = head
Hyper.Volume = .5


grapeMe(h.Parent)

local played = false

while true do

	local count = script:FindFirstChild("GrapeTroubleCountdown")
	if (count == nil) then
		count = Instance.new("IntValue")
		count.Name = "GrapeTroubleCountdown"
		count.Value = 30
		count.Parent = h
	else
		count.Value = count.Value - 1
		if (count.Value < 0) then

			local sound = Instance.new("Sound")
			sound.SoundId = "rbxasset://sounds\\Rocket shot.wav"
			sound.Parent = head
			sound.Volume = 1
			sound:play()

			local e = Instance.new("Explosion")
			e.BlastRadius = 4
			e.Position = head.Position
			
			
			e.Parent = head
				
		else
			if (Hyper.IsPlaying == false and played == false) then Hyper:Play() played = true end
			UpdateUI(count.Value)
		end
	end

	wait(1)
end



