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

What about this function does FilteringEnabled not like?

I'm having a lot of trouble figuring out how FilteringEnabled works. I've been scripting for a few months now with previous failed attempts (this is the farthest I've gotten, yes!), and this is the most confusing concept I've stumbled upon yet. I get the whole client-server model thing (or maybe not), but what I don't get is why this script won't work. What is it accessing from the client, exactly, that disallows its success? If someone could shed some light on how all of this works, that would be great. Sorry for asking for so much. Cheers.

local dialog = script.Parent
dialog.DialogChoiceSelected:connect(function(player, choice)
	local stats = player:FindFirstChild("leaderstats")
	if not stats then return end
	
	local leaflets = stats:FindFirstChild("Leaflets")
	if not leaflets then return end
	
	if choice == script.Parent.DialogChoice.DialogChoiceA.ConfirmA then
		if leaflets.Value >= 10 then
			leaflets.Value = leaflets.Value - 10
			game.ReplicatedStorage.WeaponA:Clone().Parent = player.Backpack
		end
	elseif choice == script.Parent.DialogChoice.DialogChoiceB.ConfirmB then
		if leaflets.Value >= 7 then
			leaflets.Value = leaflets.Value - 7
			game.ReplicatedStorage.WeaponB:Clone().Parent = player.Backpack
		end
	elseif choice == script.Parent.DialogChoice.DialogChoiceC.ConfirmC then
		if leaflets.Value >= 10 then
			leaflets.Value = leaflets.Value - 10
			game.ReplicatedStorage.WeaponC:Clone().Parent = player.Backpack
		end
	elseif choice == script.Parent.DialogChoice.DialogChoiceD.ConfirmD then
		if leaflets.Value >= 20 then
			leaflets.Value = leaflets.Value - 20
			local pet = game.ReplicatedStorage.Pet:Clone()
			local playerName = player.Name
			local playerCharacter = game.Workspace:FindFirstChild(player.Name)
			pet.Torso.CFrame = playerCharacter.Torso.CFrame - Vector3.new(0, 0, 5)
			pet.Name = player.Name .. "'s" .. " Clone"
			pet.Parent = playerCharacter
			pet.Pants.PantsTemplate = playerCharacter.Pants.PantsTemplate
			pet.Shirt.ShirtTemplate = playerCharacter.Shirt.ShirtTemplate
		end
	end
end)

1 comment

0

Irrelevant, but for playerCharacter I would access it form the player itself, with player.Character.

2 answers

✓ Accepted answer

I am guessing the same logic of a ClickDetector applies with dialogs.

A ClickDetector works with a client interacting with it; filtering doesn't like that. In order to make it work in filtering, you would need to have a RemoteEvent, LocalScript and a ServerScript.

Firstly, you would want to register the interaction with the ClickDetector by using the LocalScript. Remember, the client can see everything the server sees, but cannot change it. Whenever for example, the .MouseClick() event is fired, send it over to the server using a RemoteEvent, then do whatever you need to do within the ServerScript. And if you need to access the player, fear not, as .OnServerEvent returns player as its first argument.

Try applying the same logic/algorithm with dialogs.

When using FilteringEnabled, in order to access the client from server, or server from client, you need to use RemoteEvents/RemoteFunctions, or BindableFunctions/BindableEvents. In this script, you are trying to access the Player's backpack directly, and other player-objects.

What I would do is use RemoteFunctions to call the client(s), and use it to return whatever value you want from it. Hope this helps. :)

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