What do you want to achieve?
I’ve created a GUI where I type in a player’s username and item name (since I’m doing it for a hotel, I would type in the room’s number)
What is the issue?
When I type the username and room number in the TextBox and then press ‘Confirm’, it doesn’t give the item.
What solutions have you tried so far?
I’ve tried including values. I tried this for example room number’s value:
Script is inside the value, and ‘roomno’ is a TextBox inside a ScreenGui. Text should be the text inside TextBox.
I’ve made the giving script using variables and I’m pretty sure I’ve done several things wrong.
local roomNo = script.Parent.Parent.Room.Value --Value should be room # from TextBox
local user = script.Parent.Parent.Username.Value --Value should be username from TextBox
script.Parent.MouseButton1Click:Connect(function()
script.Parent.Parent.Parent.Enabled = false --Closes the Check In GUI
local tool = game.Lighting:FindFirstChild(roomNo) --Room cards from Lighting (tools: 101, 102 etc.)
local klone = tool:Clone()
if klone.Parent ~= user.Backpack then
klone.Parent = user.Backpack
end
end)
Gives error when clicking on confirm: Players.Sander_rr.PlayerGui.CheckIn.Frame.confirm.LocalScript:7: attempt to index nil with ‘Clone’
I’m a beginner to scripting and I only know very basic stuff. It could be too hard thing for me to make too, because I only know very little of scripting. Please no judging if the script is really dumb.
Oh, and also, another problem - I want the GUI to open when I click on a part. For some reason, it doesn’t open. Script inside ClickDetector:
Thanks. I unfortunately forgot to mention that the text in TextBox doesn’t even go to the Values, so I couldn’t use the values to give items. And I’m still bit confused about all this stuff.
Inside the TextButton (confirm) do I type:
?
And then inside the script inside the RemoteEvent (GiveRoom):
script.Parent.OnClientEvent:Connect(function()
local roomNo = script.Parent.Parent.Room.Value --Value should be room # from TextBox
local user = script.Parent.Parent.Username.Value --Value should be username from TextBox
script.Parent.MouseButton1Click:Connect(function()
script.Parent.Parent.Parent.Enabled = false --Closes the Check In GUI
local tool = game.Lighting:FindFirstChild(roomNo) --Room cards from Lighting (tools: 101, 102 etc.)
local klone = tool:Clone()
if klone.Parent ~= user.Backpack then
klone.Parent = user.Backpack
end
end)
end)
?
Am I doing this right or have I made it even worse now?
And yeah, there’s still issues with values. Values are empty all the time and Text from TextBox just aren’t as values.
So when someone clicks the textbox you want to fire the server with the remote event. You may also wish to send across info about what tool it is for different buttons which could look like this:
--local script
script.Parent.MouseButton1Click:Connect(function() -- button on UI which is being pressed
RemoteEvent:FireServer('Sword')-- firing server with the tool I want given
end)
-- server script
RemoteEvent:OnServerEvent:Connect(function(plr,Tool) -- by default first value will be player who fired the event, what follows is whatever values you send from the client, in this case 'Sword;
if Tool == 'Sword' -- you can do elseifs to go though different tools depending on what values are sent by the client
game.ServerStorage:FindFirstChild(Tool):Clone().Parent = plr.Backpack --now going though ServerStorage to find the tool I want (in this case Sword)
end
end)
I don’t see the purpose of that, why does he need a RemoteEvent when he can do it all on client?
Besides, an exploiter can easily fire that remote event too so it won’t really affect security.
I changed my scripts a little and used some parts of your code (thanks!)
I still get error though Workspace.GiveRoom.Script:7: attempt to index nil with ‘Clone’
Source leads to this line: game.ServerStorage:FindFirstChild(Tool):Clone().Parent = user.Backpack
It doesn’t find it because what I type into TextBox doesn’t go into ‘Text’. I have set the tool as the text in TextBox, but if I type, for example, 102 in the textbox, it doesn’t go to the Text property, it just stays empty. That’s another issue I have to fix. Same issue with the username.
So ik this was a year ago but I think I see your problem @Sander_rr
so in your script to get the text out of a textbook your doing .value but isn’t a value only for a value shouldn’t it be more like this:
local roomNo = script.Parent.Parent.Room.Text --Value should be room # from TextBox
local user = script.Parent.Parent.Username.Text --Value should be username from TextBox