Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Making a Game But Event Doesn't Fire. Help?

I'm making a DBZ game with my friend, and when we fire the event it doesn't fire. A little help?

LocalScript that is supposed to fire the event.

player = game.Players.LocalPlayer
repeat wait() until player.Character
wait(3)
character = player.Character
mouse = player:GetMouse()
local Humanoid = character.Humanoid
local animation = game.Workspace.Punch1
local dmg = 4

local Player = game.Players.LocalPlayer
local Input = game:GetService("UserInputService")

local deb = false
local punching = false

function Contact(hit)
	if deb == false and punching then
		deb = true
		if hit.Parent then
		local Stunner = hit.Parent:FindFirstChild("Stun")
		local ehuman = hit.Parent:FindFirstChild("Humanoid")
		print('maybe dood?')
		if Stunner and ehuman then
			if Stunner:IsA("BindableEvent") then
				Stunner:Fire(dmg)
				print('wot a wot woot how')
			end
		end
		end
	end
end
Input.InputBegan:connect(function(key, gpe)
	local Tag = character:FindFirstChild("HitStun")
	if key.KeyCode == Enum.KeyCode.E and Tag == nil and not gpe then
		if punching == false then
		punching = true
		T0 = Humanoid:LoadAnimation(animation)
		T0:Play()
		T0.KeyframeReached:connect(function(key)
			if key == "contact" then
				print('bam')
				character:FindFirstChild("Right Arm").Touched:connect(Contact)
			end
		end)
		T0.Stopped:connect(function()
	     deb = false
	     punching = false
	end)
		end
	end
end)

other LocalScript that is supposed to receive it.


p = game.Players.LocalPlayer
repeat wait() until p.Character~=nil
local chr = game.Players.LocalPlayer.Character
local Stunner = chr:WaitForChild("Stun")
local Int = script.Var
print(chr)
print(Int.Parent)
print(Stunner.Parent)

function Tag()
	local tag = Instance.new("BoolValue")
	tag.Name = "HitStun"
	tag.Parent = chr
	local removal = script.Removal:clone()
	removal.Parent = tag
	removal.Disabled = false
end

Stunner.Event:connect(function(dmg)
	print('received')
	local human = chr:FindFirstChild("Humanoid")
	if human then
		print('stunned')
		local var = math.random(1,2)
		Int.Value = var
		human:TakeDamage(dmg)
		if Int.Value == 1 then
			Tag()
			local T0 = human:LoadAnimation(script.Stun1)
			T0:Play()
		end
		if Int.Value == 2 then
			Tag()
			local T0 = human:LoadAnimation(script.Stun2)
			T0:Play()
		end
	end
end)

The Event does not work no matter how many times I look through.

Note: I tried to use RemoteEvents as well.

2 comments

0

does the event have a child that fires

0

I mean the bullet. does the event have anything to fire?

1 answer

✓ Accepted answer

I think I might see the problem. This is not at all how BindableEvents work.

A BindableEvent is like a local RemoteEvent. It allows for custom events to be created on a single machine. It does not replicate.

Your code, on the other hand, attempts to Fire a BindableEvent on someone else's computer.

That means, your approach is entirely wrong. For one, there is no way to directly replicate from a client to a client (it must first pass through the server). Second of all, this code completely trusts the hit event to the first client. The client is much more easily exploited. For example, Player1 could lagswitch over to someone else, beat them up, fly off, and repeat. The other player would take all the damage from the attacks all at once, and they would instantly die.

Fun.

Here is how you should code it. Have the Contact detection occur in a Server Script. Because Character Animations automatically replicate to the server, you can use the event AnimationPlayed to detect when they play the correct animation.

Keep in mind though, that the server creates a separate Animation instance for itself to replicate animations. Thus, to detect if they are using the right animation, do:

Humanoid.AnimationPlayed:Connect(function(AnimationTrack)
	if AnimationTrack.AnimationId == game.Workspace.Punch1.AnimationId then
		punching = true
	end
end)

Good luck!

Side Note: It is easier to store a variable for whether events should run their code than it is to create a function and hook it up to an event each time the condition is satisfied (which is often), and then Disconnect it once the condition ends. Instead, just use a variable and make the connection always open, but only run after the other Event sets the variable to true. I hope that makes sense.

2 comments

0

I don't understand anything, I actually can't get what you're saying. I'm just trying to figure out if I should use a RemoteEvent instead. But I'll see if this works.

0

Actually nvm I figured out way to make it work thanks so much ^.^

This discussion is preserved as it was. New answers, comments, and votes are closed.