Hey! My combat script works except for the fact that for some reason, the client cannot access a value sent by the server??? I imported all the scripts from an existing game that still work, however after moving the local scripts to a tool it doesn’t seem to work, and I believe the problem is that the client never gets the character. Here is my code:
“PunchServer” inside ServerScriptService:
local Event = game.ReplicatedStorage.Punch
local M = require(game.ReplicatedStorage.CharModule)
Event.OnServerEvent:Connect(function(Player, Action)
local c = Player.Character
if Action == "Jab1" then
local v = M:Attack(c, 5, 3, false, 0)
Event:FireAllClients("Jab1", v)
elseif Action == "Jab2" then
local v = M:Attack(c, 5, 5, false, 0)
Event:FireAllClients("Jab2", v)
else
local v = M:Attack(c, 5, 12, true, 30)
Event:FireAllClients("Jab3", v)
end
end)
LocalScript inside tool
--Variables
local Event = game.ReplicatedStorage.Punch
local P = game.ReplicatedStorage.HitFX
local SFX1 = Instance.new("Sound")
SFX1.Name = "SFX"
SFX1.SoundId = "rbxassetid://743886825"
local SFX2 = Instance.new("Sound")
SFX2.Name = "SFX"
SFX2.SoundId = "rbxassetid://2330778973"
local Player = game.Players.LocalPlayer
local Combo = 0
--Check to see when the server tells us to create the effects
Event.OnClientEvent:Connect(function(Action, c)
if Action == "Jab1" then
Combo += 1
--Create the Combo meter if the player doesnt have one, and if it does add 1 to it
if not Player.PlayerGui:FindFirstChild("ComboMeter") then
local GUI = game.ReplicatedStorage.Other.ComboMeter:Clone()
local Frame = GUI.Frame
GUI.Parent = Player.PlayerGui
Frame.Position = UDim2.new(0, math.random(0.250,0.650), 0, math.random(0.025,0.150))
GUI.Frame.ComboNumber.Text = tostring(Combo)
else
Player.PlayerGui.ComboMeter.Frame.ComboNumber.Text = tostring(Combo)
Player.PlayerGui.ComboMeter.Frame.Position = UDim2.new(0, math.random(0.250,0.650),0, math.random(0.025,0.150))
end
local NewP = P:Clone()
print(c.Name)
NewP.Parent = c.HumanoidRootPart
NewP:Emit(1)
SFX1:Play()
for i, v in pairs(c.Humanoid:GetPlayingAnimationTracks()) do
v:Stop()
end
local Stun = Instance.new("Animation")
Stun.Name = "Stun1"
Stun.AnimationId = "rbxassetid://7038293672"
local G = c.Humanoid:LoadAnimation(Stun)
G:Play()
c.Humanoid.WalkSpeed = 0
c.Humanoid.JumpPower = 0
game.Debris:AddItem(NewP, 0.7)
wait(0.4)
G:Stop()
c.Humanoid.WalkSpeed = 16
c.Humanoid.JumpPower = 50
elseif Action == "Jab2" then
Combo += 1
if not Player.PlayerGui:FindFirstChild("ComboMeter") then
local GUI = game.ReplicatedStorage.Other.ComboMeter:Clone()
local Frame = GUI.Frame
GUI.Parent = Player.PlayerGui
Frame.Position = UDim2.new(0, math.random(0.250,0.650), 0, math.random(0.025,0.150))
GUI.Frame.ComboNumber.Text = tostring(Combo)
else
Player.PlayerGui.ComboMeter.Frame.ComboNumber.Text = tostring(Combo)
Player.PlayerGui.ComboMeter.Frame.Position = UDim2.new(0, math.random(0.250,0.650),0, math.random(0.025,0.150))
end
local NewP = P:Clone()
NewP.Parent = c.HumanoidRootPart
NewP:Emit(1)
SFX2:Play()
for i, v in pairs(c.Humanoid:GetPlayingAnimationTracks()) do
v:Stop()
end
local Stun = Instance.new("Animation")
Stun.Name = "Stun2"
Stun.AnimationId = "rbxassetid://7038297002"
local G = c.Humanoid:LoadAnimation(Stun)
G:Play()
c.Humanoid.WalkSpeed = 0
c.Humanoid.JumpPower = 0
game.Debris:AddItem(NewP, 0.7)
wait(0.4)
G:Stop()
c.Humanoid.WalkSpeed = 16
c.Humanoid.JumpPower = 50
else
Combo += 1
--Create the combo meter if the player doesnt have one and add 1 if the player does
if not Player.PlayerGui:FindFirstChild("ComboMeter") then
local GUI = game.ReplicatedStorage.Other.ComboMeter:Clone()
local Frame = GUI.Frame
GUI.Parent = Player.PlayerGui
Frame.Position = UDim2.new(0, math.random(0.250,0.650), 0, math.random(0.025,0.150))
GUI.Frame.ComboNumber.Text = tostring(Combo)
else
Player.PlayerGui.ComboMeter.Frame.ComboNumber.Text = tostring(Combo)
Player.PlayerGui.ComboMeter.Frame.Position = UDim2.new(0, math.random(0.250,0.650),0, math.random(0.025,0.150))
end
local NewP = P:Clone()
NewP.Parent = c.HumanoidRootPart
NewP:Emit(1)
SFX1:Play()
for i, v in pairs(c.Humanoid:GetPlayingAnimationTracks()) do
v:Stop()
end
local Stun = Instance.new("Animation")
Stun.Name = "Stun1"
Stun.AnimationId = "rbxassetid://7038293672"
local G = c.Humanoid:LoadAnimation(Stun)
G:Play()
c.Humanoid.WalkSpeed = 0
c.Humanoid.JumpPower = 0
game.Debris:AddItem(NewP, 0.7)
wait(0.4)
G:Stop()
c.Humanoid.WalkSpeed = 16
c.Humanoid.JumpPower = 50
end
wait(1)
end)
Error is “31: attempt to index nil with ‘Name’”