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)
** You are now Level 5! **