Hello, i have a problem. When you click on the mouse button when a coconut is equipped, half a coconut should appear in inventory, All these things are in the serverStorage. help me please
This local script in coconut:
local player = game:GetService(“Players”).LocalPlayer
local coconut = player.Backpack:FindFirstChild(“Coconut”)
local halfCoconutModel = game:GetService(“ServerStorage”).Tools.HalfCoconut:Clone()
halfCoconutModel.Parent = player.Backpack
local function onButton1Down()
if coconut then
halfCoconutModel:Clone().Parent = player.Character
end
end
game:GetService(“UserInputService”).InputBegan:Connect(function(input, gameProcessedEvent)
if not gameProcessedEvent and input.UserInputType == Enum.UserInputType.MouseButton1 then
onButton1Down()
end
end)
From looking at this image I can tell its a client script. Client scripts cannot access anything related to the server. For example it can’t access ServerStorage and ServerScriptService. Only server-sided scripts can access those this could be why you are possibly getting that error message.
This would not be a good way to do it my opinion.
Since the script is in the backpack, the PlayerAdded caused by this player joining would most likely run before the script itself runs.
Also, this would every time another player joins, but we really only care about the one player in this case.
ServerScriptService and ServerStorage do not Replicate their Descendants to the Client. You can read the Documentation for it, which openly states that they do not Replicate anything to the Client.
Both ServerScriptService and ServerStorage are very Important Services for you, They allow you to store very important Assets of your game like Models, or Scripts into a Secure location that only the Server can Access, and not the Client.
The Client is basically what the Player see’s on their Screen and what is Replicated to them, Almost everything is Replicated to the Client, with the exception of the said Services, Since the other stuff replicates to the Client, they can easily be taken or Manipulated by Exploiters, while the Server is something that Exploiters cannot easily access duting runtime, which makes it important for Handling stuff.
If you intend to use stuff for both Client and Server, use the Service: ReplicatedStorage ReplicatedStorage is basically stuff shared between the Server and Client, but keep in mind that you shouldn’t trust this Service with very important things as it can be accessed by Exploiters.