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

how do I make a block spawn right next to a player?

Asked by 5 years ago

so I just want a part to spawn right next to a player. please use my variables script: Tool.Activated:Connect(function() local BlockThatHurts=Instance.new("Part",game.Workspace) BlockThatHurts.Size=Vector3.new(4.49, 4.72, 4.92) BlockThatHurts.Material="Neon" BlockThatHurts.BrickColor=BrickColor.new("Lilac") BlockThatHurts.Position = game.Players.Players.Torso.Position + Vector3.new(0,0,-5)

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

You can't do it like that...

I see you are doing R6 so I'll give you this:

First step: Put 1 Handle, 1 LocalScript, 1 Script, 1 RemoteEvent inside your Tool

Second step: Put this code inside your LocalScript

local Tool = script.Parent
local Remote = Tool.RemoteEvent

Tool.Activated:Connect(function()
    Remote:FireServer()
end)

Third step: Put this code inside your Script

script.Parent.RemoteEvent.OnServerEvent:Connect(function(player)
    local Character = player.Character or player.CharacterAdded:Wait()
    local Torso = Character:WaitForChild("Torso")
    local BlockThatHurts = Instance.new("Part", workspace)
    BlockThatHurts.Size = Vector3.new(4.49, 4.72, 4.92) -- Change if you want
    BlockThatHurts.Material = "Neon" -- Change if you want
    BlockThatHurts.BrickColor = BrickColor.new("Lilac") -- Change if you want
    BlockThatHurts.Position = Torso.Position + Vector3.new(0,0,-5) -- Change if you want
end)

Last step: Test it.

This works for Filtering Enabled and since Roblox made FE permanent, you might as well do it the FE way. Because if you do it in a single Local Script without the Remote and the Script then you will only be able to see it. Doing it this way will make it so everyone sees it.

Alternative step: Put only 1 LocalScript and 1 Handle inside your Tool and nothing else is needed for this.

-- Only you can see the spawned part if you do it this way... Client sided basically.
local Tool = script.Parent
local player = game.Players.LocalPlayer

Tool.Activated:Connect(function()
    local Character = player.Character or player.CharacterAdded:Wait()
    local Torso = Character:WaitForChild("Torso")
    local BlockThatHurts = Instance.new("Part", workspace)
    BlockThatHurts.Size = Vector3.new(4.49, 4.72, 4.92)
    BlockThatHurts.Material = "Neon"
    BlockThatHurts.BrickColor = BrickColor.new("Lilac")
    BlockThatHurts.Position = Torso.Position + Vector3.new(0,0,-5)
end)
Ad

Answer this question