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 in real game. Help?

Hey, guys. The following script is suppose to clone a Gui inside a tool and copy it to the Player's PlayerGui whenever the tool is activated (clicked once after the tool is equipped). It works perfectly in Roblox Studio, but not in the real game. If anyone explain to me what is wrong, I would gladly appreciate it.

Tool = script.Parent
Player = Tool.Parent.Parent
Character = Player.Character
mouse = Player:GetMouse()
Gui = Tool.AmmoGui
Tool.Equipped:connect(function(mouse)
    findGui = Player.PlayerGui:FindFirstChild("AmmoGui")
	if findGui then
		findGui.Frame.Visible = true
	else
		newGui = Gui:Clone()
		newGui.Parent = Player.PlayerGui
	end
end)
Tool.Unequipped:connect(function(mouse)
    findGui = Player.PlayerGui:FindFirstChild("AmmoGui")
	if findGui then
		findGui.Frame.Visible = false
	else
		print("AmmoGui wasn't found")
	end
end)

1 comment

0

Maybe because you define mouse, when in actual fact the equipped event also returns you mouse. Try not defining mouse

2 answers

✓ Accepted answer

It's likely that you have to use a local script, because it will be a descendant of a specific player. This will also allow you to use things like game.Players.LocalPlayer.

I would also recommend that you just change if the GUI is visible or not, instead of creating a new one.

WaitForChild() would probably be a good idea as well, in case the player just spawned and the GUI takes a minute to load.

Combine these things, and you can do something like this:

Tool.Equipped:connect(function(mouse)
	game.Players.LocalPlayer:WaitForChild("AmmoGui").Visible = true
end)

2 comments

0

Your answer didn't necessarily answer what I wanted, but the things you explained to me helped me to think of another solution. THANK YOU!~

0

Here's where I used this information on: http://www.roblox.com/RayCast-Gun-Experiment-place?id=170063853

To help you with these issues in the future: to test a place in a real environment, press F7 to start a server, and press Alt+F7 to play a player in said server. You can then look at any new errors that generate from your Output tab.

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