#help please it prints code works but dosent spawn the model infront of player when E is clicked

45 messages · Page 1 of 1 (latest)

brisk fossil
#

You should split it into 2 scripts, one being on the client side and the other being server side.
Client:

local tool = script.Parent
local RP = game:GetService("ReplicatedStorage")
local remoteEvent = RP:FindFirstChild("SpawnModel") -- Create a RemoteEvent in ReplicatedStorage

local userInputService = game:GetService("UserInputService")
userInputService.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.E and tool.Parent == script.Parent then
        local player = game.Players.LocalPlayer
        local character = player.Character
        local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
        if humanoidRootPart then
            local position = humanoidRootPart.Position
            remoteEvent:FireServer(position + Vector3.new(0, 0, 5)) -- Fire the RemoteEvent with the desired position
        end
    end
end)
print("code works")

Server:

local RP = game:GetService("ReplicatedStorage")
local remoteEvent = RP:FindFirstChild("SpawnModel")
local model = RP:FindFirstChild("Toad Slash") -- Replace "Model" with the name of your model

remoteEvent.OnServerEvent:Connect(function(player, position)
    local modelClone = model:Clone()
    modelClone:SetPrimaryPartCFrame(position)
    modelClone.Parent = workspace
end)
brisk fossil
#

it should work properlly

rapid wraith
#

First, the print will always work due to it being out of the scope

#

Try inputting the print inside of "if input.keyCode == Enum.KeyCode.E and tool.Parent == script.Parent then"

#

and tell me if it prints it when you press E

#

Thought so

#

remove the "and tool.Parent == script.Parent"

#

What's the error

#

It needs a CFrame

#

not a vector3

#

so just change this into a CFrame

#

And get the CFrame too of this:

#

Then use the * symbol instead of +

sage trailBOT
#

studio** You are now Level 5! **studio

rapid wraith
#

I'll make it easier

#
local position = humanoidRootPart.CFrame
model:SetPrimaryPartCFrame(position * CFrame.new(0,0,5))
-- Take this as what I stated
#

Yuh

#

yes

#

It seems like you're trying to make it server-sided

#

I'll tell ya this, you could just make the RemoteEvent, then use a localScript as to get the UserInputService

#

Then inside the OnServerEvent is where you can do what you want it to do

#

Why did you need the UIS anyway?

#

You don't have a primary part

#

You also don't need the primary part / set the primary part if you just want a part/model to spawn beside the HRP (HumanoidRootPart)

#

Ah

#

PivotTo, Move, MoveTo

wintry oar
#

Adding to this dont use SetPrimaryPartCFrame since its deprecated use PivotTo(Vec3Pos) keep in mind your model has to have a PrimaryPart for this to work

#

PivotTo()

#

Your trying to move a Model right?

rapid wraith
#

Use PivotTo

wintry oar
#

Then PivotTo

#

Also

#

Its not Vec3Pos its a CFrame my bad

#

Weld them

#

That should work

#

(WeldConstraint)

rapid wraith
#

Are the particles parented to the model

#

Nvm

wintry oar
#

Eddy can I ask you something in DM's?

rapid wraith
#

k

wintry oar
#

Yea

#

Use WeldConstraint

#

Thank eddy not me ^^ I didnt really do much since SetPrimaryPartCFrame would work

#

But it would break when Roblox removes that Method so its better use the updated one directly