Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Click detector not giving player item from replicatedstorage?

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)

2 comments

0

Do you blocked your grammarly? xD

0

would you mind pointing out my "spelling mistake". Just pointing out your mistake, "Do you blocked"

3 answers

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.

2 comments

0

it's still refusing to work

0

Do you get any errors? Are you sure RokakaFruit is in ReplicatedStorage?

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.