Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

why my crate opening system script isnt working?

yes i know i have already posted it but then deleted it coz i thought i found a solution (i didnt :/) so this is a crate opening system script and it doesnt work however im not getting any errors. i know its long but when u look deeper into it u will notice that its rly basic. any help appreciated!

local button = script.Parent
local cratedrops = game.StarterGui.CrateDrops
local plr = game.Players:WaitForChild(game.Workspace:WaitForChild("PlayerName").Value)
button.MouseButton1Click:Connect(function()
	script.Parent.Parent.Parent.Crates.Visible = false
	script.Parent.Parent.Parent.CurrentCrate.Visible = false
	script.Parent.Parent.Parent.CurrentCrate.CrateNameValue.Value = "not chosen"
	script.Parent.Parent.Parent.CurrentCrate.CrateImage.Image = script.Parent.Parent.Parent.Crates.BasicCrate.ImageLabel.Image
	script.Parent.Parent.Parent.CurrentCrate.Amount.Text = "You Own 0"
	script.Parent.Parent.Parent.CurrentCrate.Currency.Value = 30303
	script.Parent.Parent.Parent.CurrentCrate.PriceValue.Value = 0
	script.Parent.Parent.Parent.CurrentCrate.BoxName.Text = "Choose A Crate"
	if script.Parent.Parent.CrateNameValue.Value == "Basic" then
		local basicdrops = game.StarterGui.Crates.Crates.BasicCrate.Drops.Basic:GetChildren()
		local novadrops = game.StarterGui.Crates.Crates.BasicCrate.Drops.Nova:GetChildren()
		local stardrops = game.StarterGui.Crates.Crates.BasicCrate.Drops.Star:GetChildren()
		local choosenitem
		if plr:WaitForChild("Crates"):WaitForChild("Basic").Value > 0 then
			plr:WaitForChild("Crates"):WaitForChild("Basic").Value = plr:WaitForChild("Crates"):WaitForChild("Basic").Value - 1
			local chance = math.random(1,100)
			if chance >= 15 then
				choosenitem = basicdrops[math.random(1,#basicdrops)]
			elseif chance < 15 and chance > 1 then
				choosenitem = novadrops[math.random(1,#novadrops)]
			elseif chance == 1 then
				choosenitem = stardrops[math.random(1,#stardrops)]
			end
			cratedrops.DropImage.Image = cratedrops.Drops:FindFirstChild(choosenitem.Name).Image
			cratedrops.DropName.Text = "You got "..choosenitem.Parent.Name .."Tier "..choosenitem.Name"!"
			cratedrops.DropImage.Visible = true
			cratedrops.DropName.Visible = true
			plr:FindFirstChild("Inventory"):FindFirstChild(choosenitem.Name).Value = plr:FindFirstChild("Inventory"):FindFirstChild(choosenitem.Name).Value + 1
			wait(4)
			cratedrops.DropImage.Visible = false
			cratedrops.DropName.Visible = false
		end
	end
end)

1 answer

You should use RemoteEvents for this. It will make it so much easier, first insert a RemoteEvent into ReplicatedStorage, then (I'm assuming your script is in a server script) so put a Server Script inside ServerScriptStorage and put a localscript inside the button you want to click.

Also I should mention, you're getting the StarterGui instead of PlayerGui, changing the properties of the GUI's inside of StarterGui like this won't work. You will need to get the Player's PlayerGui and get the GUI's that are inside of the Player's PlayerGui, that way if you want to make changes to the Player's GUI's, that player can actually see those changes.

Code:

Local Script:

local button = script.Parent

button.MouseButton1Click:Connect(function()
	
	game.ReplicatedStorage.RemoteEvent:FireServer()
	
end)

Server Script:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr)
	
	--// Variables
	local playergui = plr.PlayerGui
	local cratedrops = playergui.CrateDrops
	
	
	--// Please make variables for all of these and specify the location so it will work.
    script.Parent.Parent.Parent.Crates.Visible = false
    script.Parent.Parent.Parent.CurrentCrate.Visible = false
    script.Parent.Parent.Parent.CurrentCrate.CrateNameValue.Value = "not chosen"
    script.Parent.Parent.Parent.CurrentCrate.CrateImage.Image = script.Parent.Parent.Parent.Crates.BasicCrate.ImageLabel.Image
    script.Parent.Parent.Parent.CurrentCrate.Amount.Text = "You Own 0"
    script.Parent.Parent.Parent.CurrentCrate.Currency.Value = 30303
    script.Parent.Parent.Parent.CurrentCrate.PriceValue.Value = 0
    script.Parent.Parent.Parent.CurrentCrate.BoxName.Text = "Choose A Crate"

    if script.Parent.Parent.CrateNameValue.Value == "Basic" then
        local basicdrops = game.StarterGui.Crates.Crates.BasicCrate.Drops.Basic:GetChildren()
        local novadrops = game.StarterGui.Crates.Crates.BasicCrate.Drops.Nova:GetChildren()
        local stardrops = game.StarterGui.Crates.Crates.BasicCrate.Drops.Star:GetChildren()

        local choosenitem
        if plr:WaitForChild("Crates"):WaitForChild("Basic").Value > 0 then
            plr:WaitForChild("Crates"):WaitForChild("Basic").Value = plr:WaitForChild("Crates"):WaitForChild("Basic").Value - 1

            local chance = math.random(1,100)
            if chance >= 15 then
                choosenitem = basicdrops[math.random(1,#basicdrops)]
            elseif chance < 15 and chance > 1 then
                choosenitem = novadrops[math.random(1,#novadrops)]
            elseif chance == 1 then
                choosenitem = stardrops[math.random(1,#stardrops)]
            end

            cratedrops.DropImage.Image = cratedrops.Drops:FindFirstChild(choosenitem.Name).Image
            cratedrops.DropName.Text = "You got "..choosenitem.Parent.Name .."Tier "..choosenitem.Name"!"
            cratedrops.DropImage.Visible = true
            cratedrops.DropName.Visible = true

            plr:FindFirstChild("Inventory"):FindFirstChild(choosenitem.Name).Value = plr:FindFirstChild("Inventory"):FindFirstChild(choosenitem.Name).Value + 1
            wait(4)
            cratedrops.DropImage.Visible = false
            cratedrops.DropName.Visible = false
        end
    end
end)

If you having any issues while testing this, post a comment below and I'll do my best to help you.

9 comments

0

ok ill try sorry for late comment

0

welp same issue :/ doesnt work, no errors

0

welp ima go sleep and check the answers tomorrow i guess

0

Are you sure the locations & stuff is right? Keep trying to find solutions. Try other things aswell and see if they will work.

0

ok ima try later

0

i think i would get errors if there was a wrong location

0

if i change starter guis to player gui and press open it changes all the values like price, crate name or currency value but it doesnt turn off guis, doesnt show the animation, doesnt give player the item and doesnt take away 1 basic crate

0

I'm sorry, I don't know what it could be. You should ask on the ScriptingHelpers discord.

0

ok i can try

This discussion is preserved as it was. New answers, comments, and votes are closed.