I can't use LocalPlayer in a serverscript but I don't know how else to reference the player. I need help.
Here's the code:
local UIS = game:GetService("UserInputService") local RS = game:GetService("ReplicatedStorage") local RE = RS.SimpleFireBall RE.onServerEvent:Connect(function(simpleFireBall) local fireBall = Instance.new("Part", workspace) fireBall.Anchored = false fireBall.Size = Vector3.new(2,2,2) fireBall.Shape = "Block" local plr = game.Players.LocalPlayer local char = plr.Character local hum = char.Humanoid fireBall.Orientation = char.LeftArm.Orientation fireBall.CFrame = char.LeftArm.CFrame * CFrame.new(1,3,0) end)
Thanks. Also here's the localscript:
local UIS = game:GetService("UserInputService") local RS = game:GetService("ReplicatedStorage") local RE = RS.SimpleFireBall UIS.InputBegan:Connect(function(input, gameProcessedEvent) if input.KeyCode == Enum.KeyCode.Z then RE:FireServer() end end)
:FireServer() actually sends the player that it is associated with to the server as the first parameter. So, you can do this:
local UIS = game:GetService("UserInputService") local RS = game:GetService("ReplicatedStorage") local RE = RS.SimpleFireBall RE.onServerEvent:Connect(function(simpleFireBall) local fireBall = Instance.new("Part", workspace) fireBall.Anchored = false fireBall.Size = Vector3.new(2,2,2) fireBall.Shape = "Block" local plr = simpleFireBall local char = plr.Character local hum = char.Humanoid fireBall.Orientation = char.LeftArm.Orientation fireBall.CFrame = char.LeftArm.CFrame * CFrame.new(1,3,0) end)
This should work. If it doesn't, leave a comment.
every time you fire a server (in a local script) the localplayer instance comes with the arguments in the onserverevent function. example:
--localscript local event = game.ReplicatedStorage.Event event:FireServer(argument)
--server local event = game.ReplicatedStorage.Event event.OnServerEvent:Connect(function(player,argument) if player ~= nil then print("got player! woo!") end end)
hope that helped