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

How to refer to a "Player" from a ServerScript without using PlayerAdded?

Asked by 4 years ago

I want the script below to weld the "shield" part to the player's right arm whenever the "G" key is pressed. However, I don't know how to refer to a player without using PlayerAdded, so what would I do in this case?

UIS = game:GetService("UserInputService")

isNear = game:GetService("ReplicatedStorage").Values.isNearShield

debounce = false



UIS.InputBegan:Connect(function(inputObj, gameProcessed)
    if gameProcessed then
        return

    elseif inputObj.KeyCode == Enum.KeyCode.G and not debounce and isNear == true then
        debounce = true


local shield = script.Parent:Clone()
shield.CanCollide = false
shield.Anchored = false
shield.Parent = player.Character

local rightArm = player.Character.RightUpperArm

local  weld = Instance.new("Weld")
      weld.Part0 = rightArm
      weld.C0 = CFrame.new(0.5, 0, 0) * CFrame.fromEulerAnglesXYZ(0, math.pi/2, 0)
      weld.Part1 = shield 
      weld.Parent = shield


    end
    wait(5)
    debounce = false
end)

0
for i,v do in pairs(game.Players:GetChildren()) do print(v.Name) end v would be the player danglt 185 — 4y
0
What is the mission? NIMI5Q -2 — 4y
0
A) This does not look like a server script. It looks like a local script. B) If it is a local script, there are many things wrong with your code. DeceptiveCaster 3761 — 4y

Answer this question