Hey! I have a problem, about a core part of my game.
-
What do you want to achieve? I am trying to make a crate opening system. You get a skin, when the crate is opened.
-
What is the issue? I click a button in a screenGui, nothing get’s printed, nothing happens. There are no errors either.
-
What solutions have you tried so far? I have changed some script lines, and some names/ But nothing is working.
I used a tutorial off YouTube for a crate opening system, and I changed it a bit. Then it broke the entire, script.
Local Script, used in the screenGui.
-- local cost = 500
local skinModule = require(game.ServerScriptService:WaitForChild("skinModule"))
local BuyBtnCrate1 = script.Parent.AnimalPage.Crate1.BuyBtn
local player = game.Players.LocalPlayer
BuyBtnCrate1.MouseButton1Click:Connect(function()
print("Click")
if player.Money.Value >= cost then
player.Money.Value = player.Money.Value - cost
local skin = skinModule.chooseRandomSkin()
print(skin.Name.." selected")
local skinVal = Instance.new("StringValue")
skinVal.Name = skin.Name
skinVal.Parent = player.SkinInventory
game.ReplicatedStorage.BreakCrate:FireClient(player,skin)
end
end)
skinModule, inside ServerScriptService.
local skinModule = {}
skinModule.skins = {
["Ultimate"] = {
game.ReplicatedStorage.CreateSkins.Dog;
};
["Legendary"] = {
game.ReplicatedStorage.CreateSkins.Dog;
};
["Epic"] = {
game.ReplicatedStorage.CreateSkins.Dog;
};
["Rare"] = {
game.ReplicatedStorage.CreateSkins.Dog;
};
["Uncommon"] = {
game.ReplicatedStorage.CreateSkins.Dog;
};
["Common"] = {
game.ReplicatedStorage.CreateSkins.Dog;
};
}
-- Weighted Selection
-- 100 total weight
skinModule.rarities = {
["Ultimate"] = 0.5; -- 0.5% chance
["Legendary"] = 4.5; -- 4.5% chance
["Epic"] = 4; -- 8% chance
["Rare"] = 12; -- 12% chance
["Uncommon"] = 32; -- 30% chance
["Common"] = 47; -- 45% chance
}
skinModule.chooseRandomSkin = function()
local randomNumber = math.random(1,100)
local counter = 0
for rarity, weight in pairs(skinModule.rarities) do
counter = counter + weight
if randomNumber <= counter then
local rarityTable = skinModule.skins[rarity]
local chosenSkin = rarityTable[math.random(1,#rarityTable)]
print(chosenSkin)
return chosenSkin
end
end
end
return skinModule
Gui Client, inside a ScreenGui. This localscript makes the camera works.
local TweenService = game:GetService("TweenService")
local camera = game.Workspace.Camera
local studio = game.Workspace.Studio
local Button = script.Parent.Button
local SkinGui = script.Parent.Skins
local template = script:WaitForChild("Template")
local scrollingFrame = script.Parent:WaitForChild("Skins"):WaitForChild("ScrollingFrame")
local buttonConnections = {}
local function setTemplateEquipped(template)
for i, v in pairs(scrollingFrame:GetChildren()) do
if v:FindFirstChild("Equipped") then
v.Equipped.Text = "UNEQUIPPED"
v.Equipped.TextColor3 = Color3.fromRGB(255,0,0)
end
end
template.Equipped.Text = "EQUIPPED"
template.Equipped.TextColor3 = Color3.fromRGB(0,225,0)
end
local function addToFrame(skin)
local newTemplate = template:Clone()
newTemplate.Name = skin.Name
newTemplate.SkinName.Text = skin.Name
newTemplate.Parent = scrollingFrame
local newSkin = skin:Clone()
newSkin.Parent = newTemplate.ViewportFrame
local camera = Instance.new("Camera")
camera.CFrame = CFrame.new(newSkin.PrimaryPart.Position + (newSkin.PrimaryPart.CFrame.lookVector * 3),newSkin.PrimaryPart.Position)
camera.Parent = newTemplate.ViewportFrame
newTemplate.ViewportFrame.CurrentCamera = camera
buttonConnections[#buttonConnections+1] = newTemplate.MouseButton1Click:Connect(function()
if newTemplate.Equipped.Text == "EQUIPPED" then
-- We Know that as it is already equipped they want to unequip it
game.ReplicatedStorage.UnequipPet:FireServer()
newTemplate.Equipped.Text = "UNEQUIPPED"
newTemplate.Equipped.TextColor3 = Color3.fromRGB(255,0,0)
else
-- We know that it is already UNEQUIPPED and now they want to equip it
game.ReplicatedStorage.EquipPet:FireServer(skin.Name)
setTemplateEquipped(newTemplate)
end
end)
end
game.ReplicatedStorage.SendData.OnClientEvent:Connect(function(data)
print("Picked Up On Client!")
for i, skinName in pairs(data) do
if game.ReplicatedStorage.CreateSkins:FindFirstChild(skinName) then
addToFrame(game.ReplicatedStorage.CreateSkins:FindFirstChild(skinName))
end
end
end)
local NotShowing = true
-- If NotShowing = True (If NotShowing is true then the thing is invis)
Button.MouseButton1Click:Connect(function()
if NotShowing == true then
SkinGui.Visible = true
NotShowing = false
elseif NotShowing == false then
SkinGui.Visible = false
NotShowing = true
end
end)
game.ReplicatedStorage.BreakCrate.OnClientEvent:Connect(function(skin)
addToFrame(skin)
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = studio.CamPart.CFrame
wait(1.5)
for i = 1, 50, 1 do
studio.Crate.Size = studio.Crate.Size + Vector3.new(0.1,0.1,0.1)
wait(0.01)
end
-- By now the crate is huge
local explosion = Instance.new("Explosion")
explosion.BlastRadius = 10
explosion.BlastPressure = 0
explosion.Position = studio.Crate.Position
explosion.ExplosionType = Enum.ExplosionType.NoCraters
explosion.DestroyJointRadiusPercent = 0
explosion.Parent = studio.Crate
studio.Crate.Transparency = 1
local skinClone = skin:Clone()
for i, v in pairs(skinClone:GetChildren()) do
if v:IsA("BasePart") then
v.Anchored = true
end
end
for i, v in pairs(studio.Confetti:GetChildren()) do
if v:IsA("ParticleEmitter") then
v.Enabled = true
end
end
skinClone:SetPrimaryPartCFrame(CFrame.new(studio.Crate.Position,studio.CamPart.Position))
skinClone.Parent = studio
local tweenInfo = TweenInfo.new(
2,
Enum.EasingStyle.Bounce,
Enum.EasingDirection.Out,
0,
false,
0
)
local tween = TweenService:Create(camera, tweenInfo, {CFrame = CFrame.new(skinClone.PrimaryPart.Position + (skinClone.PrimaryPart.CFrame.lookVector * 5) + Vector3.new(0,0.75,0),skinClone.PrimaryPart.Position) } )
tween:Play()
wait(5)
for i, v in pairs(studio.Confetti:GetChildren()) do
if v:IsA("ParticleEmitter") then
v.Enabled = false
end
end
camera.CameraType = Enum.CameraType.Custom
studio.Crate.Transparency = 0
studio.Crate.Size = Vector3.new(97.054, -36.223, 63.468)
skinClone:Destroy()
end)