I'm trying to make this game simillar to ExohdaCody's Medieval Warfare: Reforged and I'm focusing on the blacksmith right now. Here's my problem; I can't make it pull up the gui when you click the torso. I havea script in workspace.Here's my script:
local plr = game.Players.LocalPlayer while true do function PullUpGuiOnClick() game.Workspace.JimmyTheBlacksmith.Torso.OnClicked:Connect() -- i've seen this before but don't know how to use it.. game:GetService("InsertService"):LoadAsset(185218430).Parent = plr.PlayerGui game.Workspace.JimmyTheBlacksmith.TorsoOnClicked:Connect()function PulUpGuiOnClick() -- another part i'm uncertain about.. end end end
Thanks for reading! you can click here to go to the place.
There are a few things wrong with this.
One, what is the purpose of the while true do
? That will only lag your game, use a connecting function instead.
With your use of OnClicked, do you have a click detector inside of the torso? You should also place this script inside of the blacksmith model and reference the torso through the use of "script.Parent.Torso"
Like "tumadrina" stated, connect
uses a lowercase "C", not upper case.
Your connecting function isn't created correctly. You should instead be doing this --
game.Workspace.JimmyTheBlacksmith.Torso.OnClicked:connect(function(hit) -- Code goes here end)
TorsoOnClicked
is not anything native to RBX.Lua. Your use of a connecting function will make everything work correctly. If you want to reference another function, create a new function like this --
function NameHere(variablesgohere) end -- Then, you can reference the function through use of this NameHere() -- you can use any collected variables in the parenthesis to allow "variablesgohere" to take on the value of whatever you supply the function call with.
You should then create a Gui that starts out with visible set to false, and when the torso is clicked, the Gui becomes visible = true
.
Lastly, what you're doing in line 5 seems inefficient and potentially buggy. You would be much better off avoiding InsertService when possible.
If you need a more indepth explanation on anything here, let me know, and I can do my best to help out.