So I have two scripts. One is local script in StarterGui and another one is in Workspace. the script in Workspace is a normal script. I was wondering if someone can point out what I am doing wrong and correct me. Im fairly new at remote events.

Code in workspace: local ReplicatedStorage = game:GetService("ReplicatedStorage")

local createPartEvent = ReplicatedStorage:FindFirstChild("Spells")

local cooldown = "on"

local function Recieved(Players)

if cooldown ~= "off" then

local torso = Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")

local Part = Instance.new("Part")

Part.Parent = torso

Part.CFrame = torso.CFrame + torso.CFrame.LookVector * 10

cooldown = "off"

wait(10)

cooldown = "on"

wait(10)

Part:Destroy()

end

end

createPartEvent.OnServerEvent:Connect(Recieved)

------------------------Local script:

local Players = game:GetService("Players")

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Spells = ReplicatedStorage:WaitForChild("Spells")

local UIS = game:GetService("UserInputService")

local cooldown = "on"

UIS.InputBegan:Connect(function(input)

if input.UserInputType == Enum.UserInputType.Keyboard then -- Checks if the input was related to a keyboard

if input.KeyCode == Enum.KeyCode.Q then

if Players.LocalPlayer.Character then

Spells:FireServer()

end

end

end

end)

2 comments

0

The script in the workspace is better moved to ServerScriptService. Server scripts also do not have access to LocalPlayer but you can use the first argument passed by FireServer as the player who fired the event.

0

Thanks that helps I'll try it when I have time