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

Works in Studio, but not game?

It's me again! I made a new script for my game and I came across the same problem. This time I made sure everything was right and for some reason it doesn't work in the game. The deploy GUI button things does work, but not the buttons for the gun select.

Spawn = game.Workspace.Spawn
player = script.Parent.Parent.Parent.Parent
local Gun1 = game.ServerStorage.Gun1
local Gun2 = game.ServerStorage.Gun2
local GunSelected = Gun1,Gun2
local Player = game.Players.LocalPlayer

function onClicked()
	player.Character:MoveTo(Spawn.Position)
	script.Parent:Destroy()
	local GunSelectedC = GunSelected:Clone()
	GunSelectedC.Parent = Player.Backpack
end

script.Parent.MouseButton1Down:connect(onClicked)



script.Parent.Parent.Gun1GUI.MouseButton1Down:connect(function()
	GunSelected = Gun1
	print("GunSelected 1")
end)

script.Parent.Parent.Gun2GUI.MouseButton1Down:connect(function()
	GunSelected = Gun2
	print("GunSelected 2")
end)

11 comments

0

Sorry I don't know what that is. I don't think it is, but you should probably tell me what it is anyway.

0

Then no, I assume you will need to access the Mouse first...

0

Nevermind it is off

0

Access the mouse? What do you mean?

0

Read my answer below.

0

This is how I want it to work btw, I want to select the guns with a GUI and that works. Then I want to press the deploy button and it spawns with what gun you selected. It works in studio but not in the game. That is my plan

0

OH

0

Yeah sorry if I wasn't clear. :p

0

I edited my answer.

0

Didn't work D;

1 answer

✓ Accepted answer

I recoded your script to attempt to help you:

local deploy = script.Parent
local gui = deploy.Parent
local g1gui = gui["Gun1GUI"]
local g2gui = gui["Gun2GUI"]
local pgui = gui.Parent
local player = pgui.Parent
local selected = ""
local spawn = game.Workspace.Spawn

g1gui.MouseButton1Down:connect(function()
	selected = "Gun1"
end)

g2gui.MouseButton1Down:connect(function()
	selected = "Gun2"
end)

deploy.MouseButton1Down:connect(function()
	if game:GetService("ServerStorage"):FindFirstChild(selected) and player then
		local cloned = game.ServerStorage[selected]:clone()
		cloned.Parent = player.Backpack
		player.Character:MoveTo(spawn.Position)
		gui:Destroy()
	end
end)

Hope it helps

~ Taryo

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