|
I'm having trouble with this script because it works in studio, but no in game, if you have helpful tips or fixes please reply. It says in the output that character is nil- I tried all the services.
--Place in StarterPack, ignore the damage function and box,c.Part, no problem with those
local Energized = true
plr = script.Parent.Parent
c = plr.Character
hum = c.Humanoid
m = plr:GetMouse()
Torso = c.Torso
Run = game:GetService("RunService")
RS = Torso["Right Shoulder"]
LS = Torso["Left Shoulder"]
PunchSound = script.PunchSound
local combo = 0
OverHeadKick = script:WaitForChild("OverHeadKick")
SpinKick = script:WaitForChild("SpinKick")
Punch = script:WaitForChild("Punch")
hithumanoids = {}
box = c.Part
function onDamage(hit)
if hit.Parent.Humanoid then
local targethumanoid = hit.Parent.Humanoid
if targethumanoid and targethumanoid.Health>0 and not hithumanoids[targethumanoid] then
hithumanoids[targethumanoid] = true
targethumanoid:TakeDamage(25)
end
end
end
m.KeyDown:connect(function(k)
if not Energized then return end
Energized = false
k = k:lower()
if k == "q" then
print("Well, it detected the key?")
local SpinKickAnim = hum:LoadAnimation(SpinKick)
local OverHeadKickAnim = hum:LoadAnimation(OverHeadKick)
local PunchAnim = hum:LoadAnimation(Punch)
if plr and c and hum and hum.Health>0 and PunchAnim and combo == 0 then
print("There's a problem?")
PunchAnim:Play()
PunchSound:Play()
box.Touched:connect(onDamage)
combo = 1 elseif plr and c and hum and hum.Health>0 and SpinKickAnim and combo == 1 then
print("Is there a failure?")
SpinKickAnim:Play()
PunchSound:Play()
box.Touched:connect(onDamage)
combo = 2 elseif plr and c and hum and hum.Health>0 and OverHeadKickAnim and combo == 2 then
print("WHAT'S GOING ON?")
OverHeadKickAnim:Play()
PunchSound:Play()
box.Touched:connect(onDamage)
combo = 0
end
end
wait(0.4)
Energized = true
Energized = true end) |
|
|
There are four animations and a sound in the script, so add those and rename the animations to OverHeadKick, Punch, and SpinKick. Rename the sound to PunchSound |
|
|
|
I know that to use a LocalScript, the script is a LocalScript, thank you tho :P |
|
|
You need to wait for the character to load.
local c = plr.Character or plr.CharacterAdded:wait()
|
|
|
Yes I know I added that to the script already, still doesn't work.
I've tried a similar method and this one. Same output:
10:14:31.169 - Humanoid is not a valid member of Model
10:14:31.170 - Script 'Players.Player1.Backpack.Combat', Line 6
10:14:31.170 - Stack End |
|
indeimausJoin Date: 2014-09-01 Post Count: 4285 |
it might be a problem with how you're getting plr. since the script is a localscript you can use local player.
replace "plr = script.Parent.Parent" with "plr = game:GetService('Players').LocalPlayer" |
|
|
Here's the new script so far:
local Energized = true
local plr = game:GetService('Players').LocalPlayer
local c = plr.Character or plr.CharacterAdded:wait()
hum = c.Humanoid
m = plr:GetMouse()
Torso = c.Torso
Run = game:GetService("RunService")
RS = Torso["Right Shoulder"]
LS = Torso["Left Shoulder"]
PunchSound = script.PunchSound
local combo = 0
OverHeadKick = script:WaitForChild("OverHeadKick")
SpinKick = script:WaitForChild("SpinKick")
Punch = script:WaitForChild("Punch")
hithumanoids = {}
function onDamage(hit)
if hit.Parent.Humanoid then
local targethumanoid = hit.Parent.Humanoid
if targethumanoid and targethumanoid.Health>0 and not hithumanoids[targethumanoid] then
hithumanoids[targethumanoid] = true
targethumanoid:TakeDamage(25)
end
end
end
m.KeyDown:connect(function(k)
if not Energized then return end
Energized = false
k = k:lower()
if k == "q" then
print("Well, it detected the key?")
local SpinKickAnim = hum:LoadAnimation(SpinKick)
local OverHeadKickAnim = hum:LoadAnimation(OverHeadKick)
local PunchAnim = hum:LoadAnimation(Punch)
if plr and c and hum and hum.Health>0 and PunchAnim and combo == 0 then
PunchAnim:Play()
PunchSound:Play()
combo = 1 elseif plr and c and hum and hum.Health>0 and SpinKickAnim and combo == 1 then
SpinKickAnim:Play()
PunchSound:Play()
combo = 2 elseif plr and c and hum and hum.Health>0 and OverHeadKickAnim and combo == 2 then
OverHeadKickAnim:Play()
PunchSound:Play()
combo = 0
end
end
wait(0.4)
Energized = true
Energized = true end)
Same output sadly:
10:20:09.465 - Humanoid is not a valid member of Model
10:20:09.465 - Script 'Players.Player1.Backpack.Combat', Line 6
10:20:09.466 - Stack End |
|
|
local h = c:WaitForChild("Humanoid")
|
|
|
When I do different methods, the 'errors' in the output aren't there but the LocalScript still doesn't work. |
|
|
OMG, YES IT WORKED, I DIDN'T KNOW THIS WOULD WORK THANK YOU |
|
indeimausJoin Date: 2014-09-01 Post Count: 4285 |
try findFirstChild() and don't use keydown because it's deprecated |
|
|
Thanks for all your help and participation. :D |
|
|
Idk:
local plr = game.Players.LocalPlayer
repeat wait() until plr:FindFirstChild('Character')
local c = plr.Character
repeat wait() until c:FindFirstChild('Humanoid')
hum = c.Humanoid
|
|
|
The combat now works in-game, thank you guys |
|
|
If you want to check out the combat animation(no damage yet) join here:
http://www.roblox.com/games/362142436/Combat
Press Q for combat. |
|
indeimausJoin Date: 2014-09-01 Post Count: 4285 |
"Torso is not a valid member of Model"- the output in your game |
|