I have made a model that when you click should give you a fruit but it's not giving the fruit that said model should give
local player = game:GetService("Players").LocalPlayer local click = script.Parent.ClickDetector click.MouseClick:Connect(function() game.ReplicatedStorage.Items.RokakaFruit:Clone().Parent = player.Backpack end)
got it. when you got the player you added ". local player" which is not correct.when you work in a server script next time to get the player use :
local plr = game:GetService("Player")
and if you work in a local script
local plr = game.Players.LocalPlayer
You cannot get LocalPlayer from the server, but ClickDetectors always get of parameters of the player who clicked. So all you have to do is edit your code slightly.
local click = script.Parent.ClickDetector click.MouseClick:Connect(function(playerWhoClicked) game.ReplicatedStorage.Items.RokakaFruit:Clone().Parent = playerWhoClicked.Backpack end)
You can read up more on ClickDetectors here.
its a simple fix
since you cant use local player on touched event or click event, you have to use player.Backpack
and since you can change the parent of items in replicatedstorage, you put it in the lighting. so you final script is this:
local click = script.Parent.ClickDetector click.MouseClick:Connect(function(player) game.Lighting.Items.RokakaFruit:Clone().Parent = player.Backpack end)