Say if I press V how can I make it spawn say 10 studs away from the way my character is facing
✓ ANSWER ACCEPTED
How can I make a part from Instance.new come relative to the player who triggered it bykeybind?
1 answer
✓ Accepted answer
local script:
local player = game.Players.LocalPlayer
local character = player.CharacterAdded
local mouse = player:GetMouse()
mouse.KeyDown:Connect(function(key)
if key == key.lower("v") then
game.ReplicatedStorage:WaitForChild("RemoteEventnamehere"):FireServer()
print("fired")
end
end)
add a remote event and name it something server script:
game.ReplicatedStorage:WaitForChild("RemoteEvent").OnServerEvent:Connect(function(player)
local part = Instance.new("Part",game.Workspace)
part.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position + player.Character.HumanoidRootPart.CFrame.lookVector * 10)
end)
what this will do is check if you click on v and if you do then it will fire a server event that the server script will pick up and the server script will then create a part in workspace. it will then check your position and lookvector and put it 10 studs away from whatever way you are facing
2 comments
0
what is a remote event?
0
its the way a server script and a local script communicate with eachother
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Use lookvector and CFrame.