Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Works in Studio, but not in real game. Help?

Asked by 10 years ago

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)

0
Maybe because you define mouse, when in actual fact the equipped event also returns you mouse. Try not defining mouse LunaScripter 80 — 10y

2 answers

Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

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)
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!~ dpark19285 375 — 10y
0
Here's where I used this information on: http://www.roblox.com/RayCast-Gun-Experiment-place?id=170063853 dpark19285 375 — 10y
Ad
Log in to vote
1
Answered by 10 years ago

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.

Answer this question