local Player = game.Players.LocalPlayer
game:GetService('RunService').Heartbeat:Connect(function()
coroutine.wrap(function()
local Character = Player.Character or Player.CharacterAdded:Wait()
if (Character.HumanoidRootPart.Position - MiddlePos).Magnitude >= 10 then
game:GetService('UserInputService').InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.Q then
Tween1Open:Play()
end
end)
end
end)()
end)
You should’ve shown all the code before. You’re using UserInputService which is only available for the client. Meaning InputBegan wouldn’t be listened to for any player. Also, you don’t need to check if the UserInputType is Keyboard, since if the KeyCode is something, it already means they pressed a button.
Its most likely because you only check it once.
Try using a loop, for example use runservice
local RunService = game:GetService("RunService")
Plrs[Plr].CharacterAdded:Wait()
local PlayerPos = Plrs[Plr].Character:WaitForChild("Torso", 5).Position
--// If it is a client script then use renderstepped, if it is a server script then use heartbeat
RunService.RenderStepped:Connect(function()
if (MiddlePos - PlayerPos).Magnitude <= Distance.Value then
--// RunCode
end
end)
That is true. User input needs to be gotten from the client. You should get the input and check distance on the client, tell the server, and the server verify the distance.
That is just pseudo code though it is mostly correct. You will have to type and format it yourself. Just that the logic from it. That should be for i,v in pairs(table) do end