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

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

Asked by 6 years ago

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)
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 Cvieyra2test 176 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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.

0
You should explain your answer. If you dont, he will never learn lua HaveASip 494 — 6y
0
Well, you are correct, I should explain it more. I'll edit it I guess. Cvieyra2test 176 — 6y
Ad

Answer this question