Tools where working when I tested them in starterPack, but when I make store clone them from replicated storage to playersbackpack they do not work. This is the code that clones and moves it:
|
local tool = game.ReplicatedStorage:FindFirstChild(itemName) |
|
local toolClone = tool:clone() |
|
toolClone.Parent = player.Backpack |
|
|
2 Likes
Is this being called from the server or client? Also is there any errors on your Output at all?
2 Likes
No errors. this code is inside local script
1 Like
maybe try cloning them to StarterGear too?
1 Like
Sorry, to be more clear the items are getting put in the players backpack, but when I try to use them they dont work, no errors though the scripts are not disabled but they are not getting called for some reason
Ah, alright
The reason why that happens is that you’re only cloning the Tool on the client, which won’t be replicated across the server that way (And would result in a lot of breaking related errors and such)
You could workaround this by using RemoteEvents, firing from the client & receiving the tool from the server that way
--Handle your tool clone here by firing a RemoteEvent instead
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
Event:FireServer(itemName)
--Server Script that'll detect the change
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
Event.OnServerEvent:Connect(function(Player, itemName)
local tool = game.ReplicatedStorage:FindFirstChild(itemName)
local toolClone = tool:clone()
toolClone.Parent = Player.Backpack
end)
4 Likes
How do I connect the event to cloning and giving it to player?
The code examples I give should automatically detect the change for when the Event gets fired, just make sure to put the ServerScript
inside a secure place like ServerScriptService
, and your LocalScript
to where you want to fire the event (Or where you originally wanted to clone the tool on the client side)
1 Like
How will the player and item name parameters be passed into the function???
Oh wait I forgot about that
Yeah just pass your itemName
variables inside those parameters, and it should work just fine
The Player is the first argument when using OnServerEvent
, so you don’t need to define that when calling FireServer()
so it should look something like this:
Event:FireServer(itemName)
Event.OnServerEvent:Connect(function(Player, itemName)
1 Like
Umm will the player parameter be automatically given because their localscript called event or is that just not added?
The player
parameter of OnServerEvent
is automatically given when you fire to the server, you do not pass it in yourself
1 Like
OnServerEvent()
will pretty much wait for the specific player who fired it, so there’s really no need to pass that onto the local side
1 Like
Does this look about right???
The function is not getting called. I have it in a script where the gears are located is there something I am missing?
Try implementing a couple of prints to make sure that the RemoteEvent
stuff is being called? (Both on the server & client)
1 Like
The script itself in replicated storage is not getting called?
Did the client side print anything? It should look something like this: If it did, then probably it’s something having to do with the server side 
print("Event fired")
print(itemName)
Event:FireServer(itemName)
1 Like
Oh yea it works now!!!
Thankyou!!!
1 Like