Dialog Item Giver not giving the item

I am making a dialog item giver so if someone chooses an item they get the item but when I finished the scripts and everything it comes up with an error saying.

Attempt to index nil with Parent.

I put the localscript for the dialog giver in StarterPlayerScripts and I used a serverscript.

LocalScript:

local dialog = workspace.npc.Head.Dialog


local function onSelected(player, choice)
	if choice == dialog.IceCream then
		local item = game.Lighting.IceCreamCone
		game.ReplicatedStorage.BuyItem:FireServer(player, item)
	end
end

dialog.DialogChoiceSelected:Connect(onSelected)

ServerScript:

game.ReplicatedStorage.BuyItem.OnServerEvent:Connect(function(player,item)
	item:Clone().Parent = player.Backpack
end)

How do I fix this error?

When firing a remote event to the server, player is automatically passed as an argument.

Can you try doing: game.ReplicatedStorage.BuyItem:FireServer(item)

Thanks so much dude now it works.

2 Likes

Try to preform all checks on the server side! A knowledgeable can currently give themself any tool in the game.

For example, if you had a boombox gamepass I could fire the remote with the boombox as the argument and then I would get the boombox for free. This specifically may not be an issue for you, but as of now any tool in your game can be given to an exploiter through the server.

Instead of checking if choice == dialog.IceCream on the local script, fire the remote event with the argument choice and preform checks on the server

1 Like