Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can I instance a mesh into my game?

Hi, I am trying to make my script summon a part with a mesh in it. But when I do summon the part, it becomes a mesh but still looks like a part and not a thunderbolt (what the mesh is supposed to look like) how do I fix this?

Here is my script:

local player = game.Players.LocalPlayer
local character = player.CharacterAdded:Wait() 
local humanoid = character.Humanoid
local torso = character.UpperTorso
local mouse = player:GetMouse()
local thunderbolt = game.Workspace.Thunderbolt


local target



local God = player.PlayerGui.ChooseCharacter.God
--BREAKLINE--

local function onKeyPress(actionName, userInputState, inputObject)
    target = mouse.Target
    if userInputState == Enum.UserInputState.Begin then
        if God.Value == "Zeus" then  
            print("THUNDERBOLT!")
            local Thunder = Instance.new("Part")
            Thunder.Name = ("ThunderBolt")
            local mesh = Instance.new("SpecialMesh",ThunderBolt)
    
            Thunder.CFrame = CFrame.new(target.Position) 
            Thunder.Parent = workspace
            

        end
    end
end

game:GetService("ContextActionService"):BindAction(
    "keyPress", 
    onKeyPress, 
    false, 
    Enum.KeyCode.R,
    Enum.KeyCode.E
)

1 answer

✓ Accepted answer

Get your mesh, get the mesh ID and your texture ID, and edit it using a property script. Also, you put ThunderBolt instead of Thunder.

local player = game.Players.LocalPlayer
local character = player.CharacterAdded:Wait() 
local humanoid = character.Humanoid
local torso = character.UpperTorso
local mouse = player:GetMouse()
local thunderbolt = game.Workspace.Thunderbolt


local target



local God = player.PlayerGui.ChooseCharacter.God
--BREAKLINE--

local function onKeyPress(actionName, userInputState, inputObject)
    target = mouse.Target
    if userInputState == Enum.UserInputState.Begin then
        if God.Value == "Zeus" then  
            print("THUNDERBOLT!")
            local Thunder = Instance.new("Part")
            Thunder.Name = ("ThunderBolt")
            local mesh = Instance.new("SpecialMesh",Thunder)
            mesh.MeshId = "MESH ID HERE"
            mesh.TextureId = "TEXTURE ID HERE"
            Thunder.CFrame = CFrame.new(target.Position) 
            Thunder.Parent = workspace


        end
    end
end

game:GetService("ContextActionService"):BindAction(
    "keyPress", 
    onKeyPress, 
    false, 
    Enum.KeyCode.R,
    Enum.KeyCode.E
)

2 comments

0

ohhh ok thx!

0

no problem!

This discussion is preserved as it was. New answers, comments, and votes are closed.