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

How do I get a tool to spawn a brick in front of the player when a key is pressed?

Asked by 3 years ago

I'm trying to make a revolver that upon pressing 'e', a brick appears. I've been looking for a while, and I came across multiple people saying that in order to find the Torso of a character, it needs to be a local script. How can I make bricks spawn in front of the player without being client sided?

Basically, this is what I have so far. (The Local script.)

local tool = script.Parent
local UserInputService = game:GetService("UserInputService")
local connection
local player = game.Players.LocalPlayer


local function Connect()
    connection = UserInputService.InputBegan:Connect(function(input, gp)
        if gp then return end

        if input.KeyCode == Enum.KeyCode.E then 
            script.RemoteEvent:FireServer()
            end

    end)
end



local function Disconnect()
    connection:Disconnect()
end

tool.Equipped:Connect(Connect)
tool.Unequipped:Connect(Disconnect)

(The Regular script.)

local player = game.Players.LocalPlayer
local wepen = script.Parent.Parent.Parent
script.Parent.OnServerEvent:Connect(function(Player)
    local brick = Instance.new("Part",workspace)
    brick.Parent = workspace
    brick.CFrame = wepen.CFrame*CFrame.new(0,0,-5)
    wait(3)
    brick.Transparency = 0.1
    wait(0.05)
    brick.Transparency = 0.2
    wait(0.05)
    brick.Transparency = 0.3
    wait(0.05)
    brick.Transparency = 0.4
    wait(0.05)
    brick.Transparency = 0.5
    wait(0.05)
    brick.Transparency = 0.6
    wait(0.05)
    brick.Transparency = 0.7
    wait(0.05)
    brick.Transparency = 0.8
    wait(0.05)
    brick.Transparency = 0.9
    wait(0.05)
    brick.Transparency = 1
    wait(1)
    brick:Destroy()

end) 

Anytime I at least try to find the Torso, I always get an error.

0
On Line 1 of your "Regular Script", which I am assuming is a Script, is trying to find the LocalPlayer, which is what only LocalScripts can do. andarwniceguyjr 0 — 3y

2 answers

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

The detection of pressing e:


local player = game.Players.LocalPlayer local mouse = player:GetMouse() mouse.KeyDown:connect(function(key) if key == "e" then print("Pressed e") end end)

The Plain old script:


local Players = game:GetService(“Players”) local wepen = script.Parent.Parent.Parent script.Parent.OnServerEvent:Connect(function(Player) local brick = Instance.new("Part",workspace) brick.Parent = workspace brick.CFrame = wepen.CFrame*CFrame.new(0,0,-5) wait(3) brick.Transparency = 0.1 wait(0.05) brick.Transparency = 0.2 wait(0.05) brick.Transparency = 0.3 wait(0.05) brick.Transparency = 0.4 wait(0.05) brick.Transparency = 0.5 wait(0.05) brick.Transparency = 0.6 wait(0.05) brick.Transparency = 0.7 wait(0.05) brick.Transparency = 0.8 wait(0.05) brick.Transparency = 0.9 wait(0.05) brick.Transparency = 1 wait(1) brick:Destroy() end)
0
thank you, it worked! Funadonokami 4 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

maybe try changing this to the regular script

script.Parent.OnServerEvent:Connect(function(Player)
    local brick = Instance.new("Part",workspace)
    brick.Parent = workspace
    brick.CFrame = Player.Character.Torso.CFrame*CFrame.new(0,0,-5)
    wait(3)
    brick.Transparency = 0.1
    wait(0.05)
    brick.Transparency = 0.2
    wait(0.05)
    brick.Transparency = 0.3
    wait(0.05)
    brick.Transparency = 0.4
    wait(0.05)
    brick.Transparency = 0.5
    wait(0.05)
    brick.Transparency = 0.6
    wait(0.05)
    brick.Transparency = 0.7
    wait(0.05)
    brick.Transparency = 0.8
    wait(0.05)
    brick.Transparency = 0.9
    wait(0.05)
    brick.Transparency = 1
    wait(4)
    brick:Destroy()

end) 

Answer this question