Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Click detector not giving player item from replicatedstorage?

Asked by 5 years ago

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)
0
Do you blocked your grammarly? xD Xapelize 2658 — 5y
0
would you mind pointing out my "spelling mistake". Just pointing out your mistake, "Do you blocked" DraconianSG 58 — 5y

3 answers

Log in to vote
0
Answered by
seikkatsu 110
5 years ago

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
Ad
Log in to vote
0
Answered by
pwx 1581 Moderation Voter
5 years ago

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.

0
it's still refusing to work DraconianSG 58 — 5y
0
Do you get any errors? Are you sure RokakaFruit is in ReplicatedStorage? pwx 1581 — 5y
Log in to vote
0
Answered by
3wdo 198
5 years ago

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)

Answer this question