Загрузка данных
-- Roblox LocalScript: Movable GUI with Add Button and Villain Chance Increment
-- Place in StarterPlayerScripts or a LocalScript inside a ScreenGui
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local roleRemote = ReplicatedStorage:FindFirstChild("RoleAssignmentEvent")
-- Variables
local isDragging = false
local dragStart = nil
local dragOffset = nil
local currentChance = 0.25 -- Default 25%
local chanceIncrement = 0.05 -- 5% per click
-- Create main GUI
local screenGui = Instance.new("ScreenGui")
screenGui.Name = "VillainChanceGUI"
screenGui.Parent = LocalPlayer.PlayerGui
screenGui.ResetOnSpawn = false
-- Main Frame (Movable)
local mainFrame = Instance.new("Frame")
mainFrame.Size = UDim2.new(0, 250, 0, 150)
mainFrame.Position = UDim2.new(0.5, -125, 0.5, -75)
mainFrame.BackgroundColor3 = Color3.new(0.1, 0.1, 0.15)
mainFrame.BackgroundTransparency = 0.1
mainFrame.BorderSizePixel = 2
mainFrame.BorderColor3 = Color3.new(0.3, 0.8, 0.3)
mainFrame.Active = true
mainFrame.Draggable = false -- We handle drag manually
mainFrame.Parent = screenGui
-- Title Bar (for dragging)
local titleBar = Instance.new("Frame")
titleBar.Size = UDim2.new(1, 0, 0, 30)
titleBar.BackgroundColor3 = Color3.new(0.2, 0.2, 0.3)
titleBar.BackgroundTransparency = 0.2
titleBar.BorderSizePixel = 1
titleBar.BorderColor3 = Color3.new(0.3, 0.8, 0.3)
titleBar.Parent = mainFrame
local titleLabel = Instance.new("TextLabel")
titleLabel.Size = UDim2.new(1, 0, 1, 0)
titleLabel.BackgroundTransparency = 1
titleLabel.Text = "VILLAIN CHANCE CONTROLLER"
titleLabel.TextColor3 = Color3.new(0.8, 1, 0.8)
titleLabel.TextScaled = true
titleLabel.Font = Enum.Font.SourceSansBold
titleLabel.Parent = titleBar
-- Close Button
local closeBtn = Instance.new("TextButton")
closeBtn.Size = UDim2.new(0, 25, 1, -4)
closeBtn.Position = UDim2.new(1, -30, 0, 2)
closeBtn.BackgroundColor3 = Color3.new(0.8, 0.1, 0.1)
closeBtn.Text = "X"
closeBtn.TextColor3 = Color3.new(1, 1, 1)
closeBtn.TextScaled = true
closeBtn.Font = Enum.Font.SourceSansBold
closeBtn.BorderSizePixel = 1
closeBtn.BorderColor3 = Color3.new(1, 1, 1)
closeBtn.Parent = titleBar
closeBtn.MouseButton1Click:Connect(function()
screenGui.Enabled = false
end)
-- Current Chance Display
local chanceDisplay = Instance.new("TextLabel")
chanceDisplay.Size = UDim2.new(0.9, 0, 0, 30)
chanceDisplay.Position = UDim2.new(0.05, 0, 0.3, 5)
chanceDisplay.BackgroundTransparency = 1
chanceDisplay.Text = "Current Chance: " .. math.floor(currentChance * 100) .. "%"
chanceDisplay.TextColor3 = Color3.new(1, 1, 1)
chanceDisplay.TextScaled = true
chanceDisplay.Font = Enum.Font.SourceSans
chanceDisplay.Parent = mainFrame
-- "Add 5%" Button
local addBtn = Instance.new("TextButton")
addBtn.Size = UDim2.new(0.4, -10, 0, 35)
addBtn.Position = UDim2.new(0.05, 0, 0.6, 0)
addBtn.BackgroundColor3 = Color3.new(0.1, 0.5, 0.1)
addBtn.Text = "+5%"
addBtn.TextColor3 = Color3.new(1, 1, 1)
addBtn.TextScaled = true
addBtn.Font = Enum.Font.SourceSansBold
addBtn.BorderSizePixel = 2
addBtn.BorderColor3 = Color3.new(0.3, 0.8, 0.3)
addBtn.Parent = mainFrame
-- "Reset to 25%" Button
local resetBtn = Instance.new("TextButton")
resetBtn.Size = UDim2.new(0.4, -10, 0, 35)
resetBtn.Position = UDim2.new(0.55, 0, 0.6, 0)
resetBtn.BackgroundColor3 = Color3.new(0.4, 0.2, 0.2)
resetBtn.Text = "RESET"
resetBtn.TextColor3 = Color3.new(1, 1, 1)
resetBtn.TextScaled = true
resetBtn.Font = Enum.Font.SourceSansBold
resetBtn.BorderSizePixel = 2
resetBtn.BorderColor3 = Color3.new(0.8, 0.3, 0.3)
resetBtn.Parent = mainFrame
-- Status Label
local statusLabel = Instance.new("TextLabel")
statusLabel.Size = UDim2.new(0.9, 0, 0, 20)
statusLabel.Position = UDim2.new(0.05, 0, 0.85, 0)
statusLabel.BackgroundTransparency = 1
statusLabel.Text = "Ready"
statusLabel.TextColor3 = Color3.new(0.5, 0.8, 0.5)
statusLabel.TextScaled = true
statusLabel.Font = Enum.Font.SourceSans
statusLabel.Parent = mainFrame
-- Update chance display function
local function updateDisplay()
chanceDisplay.Text = "Current Chance: " .. math.floor(currentChance * 100) .. "%"
end
-- Add button logic
addBtn.MouseButton1Click:Connect(function()
currentChance = math.min(currentChance + chanceIncrement, 1.0)
updateDisplay()
statusLabel.Text = "Chance increased to " .. math.floor(currentChance * 100) .. "%"
statusLabel.TextColor3 = Color3.new(0.3, 0.9, 0.3)
-- Send updated chance to server via remote (if available)
if roleRemote then
roleRemote:FireServer("SetChance", currentChance)
end
end)
-- Reset button logic
resetBtn.MouseButton1Click:Connect(function()
currentChance = 0.25
updateDisplay()
statusLabel.Text = "Reset to 25%"
statusLabel.TextColor3 = Color3.new(0.8, 0.8, 0.3)
if roleRemote then
roleRemote:FireServer("SetChance", currentChance)
end
end)
-- DRAGGING LOGIC (Manual)
local function startDrag(input)
if not titleBar then return end
isDragging = true
dragStart = input.Position
dragOffset = mainFrame.Position
end
local function updateDrag(input)
if not isDragging then return end
local delta = input.Position - dragStart
local newX = dragOffset.X.Offset + delta.X
local newY = dragOffset.Y.Offset + delta.Y
-- Clamp to screen edges
local screenSize = screenGui.AbsoluteSize
local frameSize = mainFrame.AbsoluteSize
newX = math.clamp(newX, 0, screenSize.X - frameSize.X)
newY = math.clamp(newY, 0, screenSize.Y - frameSize.Y)
mainFrame.Position = UDim2.new(0, newX, 0, newY)
end
local function endDrag()
isDragging = false
end
-- InputBegan for drag start
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
local mousePos = Vector2.new(input.Position.X, input.Position.Y)
-- Check if click is on title bar (absolute coordinates)
local absPos = mainFrame.AbsolutePosition
local absSize = mainFrame.AbsoluteSize
local titleBarHeight = 30
if mousePos.X >= absPos.X and mousePos.X <= absPos.X + absSize.X and
mousePos.Y >= absPos.Y and mousePos.Y <= absPos.Y + titleBarHeight then
startDrag(input)
end
end
end)
-- InputChanged for drag update (Mouse movement)
UserInputService.InputChanged:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.UserInputType == Enum.UserInputType.MouseMovement and isDragging then
updateDrag(input)
end
end)
-- InputEnded for drag stop
UserInputService.InputEnded:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 and isDragging then
endDrag()
end
end)
-- Keyboard shortcut: Toggle GUI with 'V' key
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.V and input.UserInputType == Enum.UserInputType.Keyboard then
screenGui.Enabled = not screenGui.Enabled
end
end)
-- Server sync: listen for chance updates from server (optional)
if roleRemote then
roleRemote.OnClientEvent:Connect(function(data)
if type(data) == "number" then
currentChance = math.clamp(data, 0, 1)
updateDisplay()
statusLabel.Text = "Chance synced: " .. math.floor(currentChance * 100) .. "%"
statusLabel.TextColor3 = Color3.new(0.5, 0.5, 1)
end
end)
end
print("Movable Villain Chance GUI loaded. Press 'V' to toggle.")