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

How do I get to the player from a click in FE?

Asked by
Scaii_0 145
6 years ago

I have a part in workspace that should get to a script in ServerScriptService. The part has a ClickDetector and a Script saying:

script.Parent.ClickDetector.MouseClick:connect(function(Player)
    game.ReplicatedStorage:WaitForChild("BindableFunction"):InvokeServer(script.Parent) --Here
print('Click sent')
end)

The script in ServerScriptService says:

local Listener = game.ReplicatedStorage.BindableFunction 
function Listener.OnInvoke(Player, Brick)
    print('Click Received')
    wait(0.3)
    local t = Player.leaderstats.Tokens --Here

However, I get the output of 'leaderstats' is not a valid member of Part in the marked places. Both places have the same output.

How would I make the script get to the player instead of the part? And before I get any comments like 'just switch them around'. That doesn't work.

0
Thanks for marking mine as your answer, I'm glad I could help! DatOneRandomDude 69 — 6y

2 answers

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

You do not need a BindableFunction for this, it just makes it more complicated.

The solution is just have a script in SSS(ServerScriptService) and have this in it:

local part = game:GetService("Workspace"):WaitForChild("YOUR PART HERE")
local clickDetector = part:WaitForChild("ClickDetector")
local players = game:GetService("Players")

clickDetector.MouseClick:Connect(function(plr)
         plr.leaderstats.Tokens --and do your stuff here. If it doesn't work, it probably returns the character model instead of the player object, so just do:
         local player = players:GetPlayerFromCharacter(plr)
         player.leaderstats.Tokens --code here
end)

You don't need a BindableFunction. It is unnecessary because you can do it without it with much better efficiency.

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

Wow, you over complicated this. To start, you don't need that bindable function, you just do this:

workspace.MyPart.ClickDetector.MouseClick:Connect(function(PlayerThatClicked)
    print(PlayerThatClicked.Name) -- SebbyTheGODKid
    -- Code here
end)

Second thing, InvokeServer() only works on Remote Functions, and you used it on a bindable.

Bindable Function:

local MyBindable = Instance.new("BindableFunction")
MyBindable.OnInvoke = function(argument)
    print(argument)
end)
MyBindable:Invoke("this will be printed") -- > "this will be printed"

vs. Remote Function:

local MyRemote = Instance.new("BindableFunction")
MyRemote.OnServerInvoke = function(argument)
    print(argument)
end)
-- Called from the client:
MyRemote:InvokeServer("this will be printed") -- > "this will be printed"

I hope this clears it up.

Also, for the part about the tokens, if it's a value then you need to do workspace.MyValue.Value NOT workspace.MyValue because "MyValue" is not a valid member of workspace.

Extra resources:

0
He should have the script in SSS, not Workspace. SSS is a lot safer. (see my answer below) DatOneRandomDude 69 — 6y

Answer this question