So I have been having issues with this for a long time now. I am sure it is easy to some people so I need your guys’ help. So I have IntValues that hold the name for the tool. What I want it to do, is locate the name of the tool in replicated storage and then clone it in the players backpack. For example, lets say the value name was Business Class Ticket. I want the script to look through replicated storage, find that tool with that name, and then clone it into the players backpack.
I am not asking for a script, but just a couple lines of codes that can do that. I have been looking all over youtube for this but could not come up with a single thing. Thanks.
local Tool = game.ReplicatedStorage:WaitForChild("Tool")
game.Players.PlayerAdded:Connect(function(player)
local Clone = Tool:Clone()
Clone.Parent = player.Backpack
end)
I don’t really understand what you want, could you explain it better?
You want to use :FindFirstChild or :WaitForChild using the StringValue.Value Then clone the item and send it to the players backpack. Meaning define the player then do ClonedItem.Parent = player.Backpack
Use the string value to locate the item
Yeah sure. So I am making a self check-in for my airline. When you step on the part a gui pops up with a loading screen. The script checks your rank and if you are one of the certain ranks, it gives you the ticket corresponding to the rank. For example, if I am economy or the second rank value, and I step on the brick, the script would identify that I am the second rank value which is the EconomyClassTicket. It then searches through replicated storage for the tool with that name and clones it into the players backpack. Hopefully I explained it better.
Yes you did it much better, if the tool is the same is the rank you can just use :FindFirstChild(ranks name here)
and the clone it to the players backpack
If you are using a GUI, make sure you are using remote events, fired from the client as they communicate with the server, see here for details: RemoteEvent | Documentation - Roblox Creator Hub
To answer you’re question, I would use StringValues instead of IntegerValues, so lets say your StringValues value was “Business class” you could do something like this in your server side remote event script, the arguments passed by the client being toolname which you can define as your StringValue.Value on the client
game.ReplicatedStorage.RemoteEventName.OnServerEvent:Connect(function(plr, toolname)
local clone = game.ReplicatedStorage:FindFirstChild(toolname):Clone()
clone.Parent = plr.Backpack
end)
Hope this helps, leave a reply if you need some further explanation
Do you mind writing the code that locates the item with the string value? I feel like I am off.
local stringValue = game.locationOfStringvalue
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--[[
local player = game.Players.LocalPlayer -- localscript version or
local player = -- method of getting the player
]]--
local itemToClone = ReplicatedStorage:WaitForChild(stringValue.Value):Clone()
itemToClone.Parent = player:WaitForChild("Backpack")
There are many other methods of obtaining what you’re trying to do, this is just my quick method of doing so.
How do I make a variable of the player in a server script?
game.Players.PlayerAdded:Connect(function(player)
-- code here
end)
I recommend you browse the Developer Hub for more API refrence and service functions and tips.
(the above code is assuming this is in a server script located in ServerScriptService)
Would saying this work:
Brick.Touched:Connect(function(other,plr)
since there is “plr” in the parenthesis?
No, the .Touched event works differently, I’ll dm you through here and help you out so this doesn’t clutter anymore.
Okay. 30 charrrrssssssssssssssssssss
Through messages on the forum or on discord?