[repost, please reply!] script isnt doing anything, including prints

hey so im trying to make it so my script does something in this function once it recieves a remote event firing, the event fires but nothing seems to happen.

here’s the code, im not really sure what went wrong but there arent any errors

local weaponinfo = {
	physical = true,
	fist = true,
	damage = 4.5,
}
local tool = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = game:GetService("Players"):GetPlayerFromCharacter(tool.Parent)
if player then
local character = player.Character
	
local handlerfolder = character:WaitForChild("handlerfolder")
local remfolder = handlerfolder:WaitForChild("Remotes")
local m1 = remfolder:WaitForChild("M1")
print("one")


m1.OnServerEvent:Connect(function(plr)
	print("two")
	local player = game:GetService("Players"):GetPlayerFromCharacter(tool.Parent)
	if player then
		local character = player.Character
	local Humanoid = character.Humanoid
	local setupfolder = character.setupfolder
	local combo = setupfolder.Combo
	local combotimer = setupfolder.ComboTimer
	print("three")
	local function checkForStun(festy)
		for _, tag in pairs(festy) do
			if character:FindFirstChild(tag) then
				return true
			end
		end
	end
		
	if checkForStun({"Stun", "Action", "Knocked", "Blocking", "Casting"}) then return end
		
	if tick() - combotimer.Value > 2.25 then
		combo.Value = 0
	end
	print("four")
		
	if combo.Value >=4 then
		combo.Value = 3
	end
		
	combotimer.Value = tick()
	
	combo.Value += 1
	
	local animation = Humanoid:LoadAnimation(ReplicatedStorage.Animations:FindFirstChild("Hit".. combo.Value))
	animation:Play()
	print("five")
	task.wait(0.35)
	if combo.Value >=4 then
		weaponinfo.knockback = true
		weaponinfo.ragdoll = true
			end
	end
	end)
end
3 Likes

Can you post which of the prints are displayed in your output log? Can you post where the events are fired from the LocalScript?

2 Likes

youre checking if the tool is the parent of the players character instantly after the script runs, if its not then the script is not gonna run, replace the lines with repeat task.wait() until player

2 Likes

none of them print, im going to try what the other person suggested though then ill reply back

2 Likes

i really doubt i did it right but i changed the line to

local player = game:GetService(“Players”):GetPlayerFromCharacter(tool.Parent) repeat task.wait()
** until player**
local character = player.Character

i tried

repeat.taskwait()
local player = game:GetService(“Players”):GetPlayerFromCharacter(tool.Parent) repeat task.wait()
until player

but that made it so that player was unknown global player to other parts in the script which use player.

im guessing there is a correct way to do it because what i did sure didn’t work

2 Likes
local player: Player
repeat
    player = game:GetService("Players"):GetPlayerFromCharacter(tool.Parent)
    task.wait()
until player ~= nil

The idea is to repeat trying to get the player until it succeeds. This should only be applicable if your tool cannot be unequipped or dropped. Does your tool spawn directly in the player’s character, or do you give it to the player’s backpack or workspace?

3 Likes

Does the script even run? make a print at the very first line

2 Likes

they would start with this one yeah, but it’s subject to change based on what weapon they choose to use
other than that they always start with whatever weapon they have in their backpack and it isnt droppable

2 Likes

this had a lot of errors in the script, i assume by != you mispelled and meant ~= right?
i also removed local player since there were less errors that way and i dont think it was necessary… i think?
heres the script after editing that and adding it in

3 Likes

I did mean ~= but local player beforehand is necissary. local player: Player is even better. I copied your text from the forums so those quotes in GetService aren’t real ascii quotes. I’ve edited my post.

2 Likes

changed it again, ive been consistently getting this unknown global character in a lot of iterations of getting this script to work.
image

2 Likes

you need to define character variable, it was defined before as

local character = player.Character

but you could also use tool.Parent like you are to GetPlayerFromCharacter

3 Likes

ohhh i see i didnt read it haha

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.