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

How can i make my FE Tool giver work, giving a tool to the client?

I'm just trying to make an exe horror game, and i know i got alot of fe stuff to make and i really need help on this. I could learn from questions you put down, maybe i can learn from it.

I hope you can help me out a lil' and i don't want to act like an idiot here.

--LocalScript

script.Parent.CD.MouseClick:Connect(function(player)
	game.ReplicatedStorage.GiveRegularKey:FireServer()
end) 

--ServerScript

local client = game.Players.LocalPlayer
	game.ReplicatedStorage.GiveRegularKey.OnServerEvent:Connect(function()
		game.ReplicatedStorage.key:Clone().Parent = client.Backpack
	end)

1 comment

0

Although I do not specialize in Local-Server communications, I can right away assume that "client" is nil. The server cannot get "LocalPlayer" from Players since it's not a localscript

1 answer

✓ Accepted answer

Although I do not specialize in client-server communications as I stated in my comment, I will do my best to provide a solution.

LOCALSCRIPT:

script.Parent.CD.MouseClick:Connect(function(player)
	game.ReplicatedStorage.GiveRegularKey:FireServer()
end) 

SERVERSCRIPT:

game.ReplicatedStorage.GiveRegularKey.OnServerEvent:Connect(function(client)
	game.ReplicatedStorage.key:Clone().Parent = client.Backpack
end)

I haven't tested it, but by reference from: https://wiki.roblox.com/index.php?title=Remote_Functions_%26_Events#Client_to_Server

It should by theory work.

Edit (HaveASip recommended it): There was nothing wrong with the local script BUT there was a problem with the server script. As I did mention in my comment:

local client = game.Players.LocalPlayer

would never work in a server script, it only works in local scripts.

And as you saw here:

game.ReplicatedStorage.GiveRegularKey.OnServerEvent:Connect(function(client)

The 'client' in the function thing, the parameters is the player argument that all Client-To-Server provide. You'll always need to provide a player argument when adding parameters to an event.

2 comments

0

You should explain your answer. If you dont, he will never learn lua

0

Well, you are correct, I should explain it more. I'll edit it I guess.

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