Hi everyone!
I want to get the player who fired a server event... Is that possible?
local script
local mouse = game.Players.LocalPlayer:GetMouse()
local uis = game:GetService("UserInputService")
mouse.KeyDown:connect(function(key)
key = key:lower()
if key == "1" then
local main = script.Parent.Parent.Parent.Parent
if main.Visible == true then
local player = game.Players.LocalPlayer.Name --Gets the player name
local remote = game.ReplicatedStorage.Events.PurchasePrints --remote
local char = game.Players.LocalPlayer.Character --Players Char
local torso = char:WaitForChild("HumanoidRootPart") --HRP
local pos = torso.CFrame --Gets the CFrame of the Plr
remote:FireServer(pos, player) --Sending The Server the CFrame Pos and the Player name
print(pos)
local Folder = Instance.new("Folder")
Folder.Name = game.Players.LocalPlayer.Name -- This makes a new folder to hold CFrame Values of players
Folder.Parent = game.Workspace.CFrames
local Cframe = Instance.new("CFrameValue")
Cframe.Name = "CFrameValue" --Making the actual CFrameValue
Cframe.Parent = Folder
Cframe.Value = pos
print("Remote Fired Correctly! You did it for once!")
else
print("Shop Menu Not Open! Press E To Open!")
end
end
end)
server script
remote = game.ReplicatedStorage.Events.PurchasePrints
remote.OnServerEvent:Connect(function(player)
if game.Players.LocalPlayer.leaderstats.Money >= 0 then --Checking if the player who fired the event has enough money
local printer = game.ReplicatedStorage.OtherEnts.MoneyPrinter:Clone()
printer.Parent = game.Workspace.Ents
printer.Name = player.Name
local printerpos = game.Workspace.CFrames:WaitForChild(player.Name) --Gets the Cframe value in the folder and takes the cloned printer and teleports it to the hrp
local printerposval = printerpos.CFrameValue
printer.CFrame = CFrame.new(printerposval.Value)
print("Printer Spawned!")
end
end)
If you have any idea on how to do this, answers would be greatly appreciated! Thank You All!
