Slap Attack that Kicks You

So, I have created a gamepass, that makes it so that if you kill someone, they get kicked out of the game. Now there is an error occuring, but there isn’t anything thats wrong in the script, or errors in the output. It simply just doesn’t work. Here’s an image from my friend who was testing it, he has bought the gp, but it still says no GP.

Here is my script:

This is the Slap Server Script:

game.ReplicatedStorage.Slaperu.OnServerEvent:Connect(function(Player)
	local mps = game:GetService("MarketplaceService")
	local char = Player.Character or Player.CharacterAdded:Wait()
	local hum = char:FindFirstChild("Humanoid")
	local Kick = hum:LoadAnimation(script:WaitForChild("Kick"))
	local HumRP = char:WaitForChild("HumanoidRootPart")
	Kick:Play()
	local HitBox = script:WaitForChild("HitBox"):Clone()
	HitBox.CFrame = char:FindFirstChild("Right Arm").CFrame
	HitBox.Parent = char:FindFirstChild("Right Arm")

	local Pweld = Instance.new("Weld")
	Pweld.Part0 = HitBox
	Pweld.Part1 = char:FindFirstChild("Right Arm")
	Pweld.C0 = HitBox.CFrame:inverse() * char:FindFirstChild("Right Arm").CFrame
	Pweld.Parent = Pweld.Part0

	HitBox.Touched:Connect(function(Hit)
		if Hit:IsA("Part") or Hit:IsA("MeshPart") then
			if Hit.Parent ~= char then
				local EHumRP = Hit.Parent:FindFirstChild("HumanoidRootPart")
				local Humanoid = Hit.Parent:FindFirstChild("Humanoid")

				if Humanoid then
					HitBox:Destroy()
				if Hit.Parent:FindFirstChild('Right Arm') then
			
				
						
						    Hit.Parent:FindFirstChild("Humanoid"):TakeDamage(25)
							local vel = Instance.new("BodyVelocity",EHumRP)
							vel.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
							vel.Velocity = HumRP.CFrame.lookVector * 40
							wait(1)
						vel:Destroy()
						if Humanoid.Health < 1 then

						
							Player.leaderstats.moneys.Value = Player.leaderstats.moneys.Value + 50
							if 	Player and mps:UserOwnsGamePassAsync(Player.UserId,23171784)  then 
							if game.StarterGui.KickGUI.Enabled == false then
								
								local plr = game.Players:GetPlayerFromCharacter(Hit.Parent)	
									plr:Kick("You've been kicked by someone who wasted their money")
								else
									print("not on")
								end
							
							end
						end
						
						
					end
					end
					end
					end	
					end)
					end)
			

			
					
					
								
			

This is the local script in the gui:

local mps = game:GetService("MarketplaceService")
script.Parent.MouseButton1Click:Connect(function(plr)
	
	if plr and mps:UserOwnsGamePassAsync(plr.UserId, 23171784) then
	if game.StarterGui.KickGUI.Enabled == true then
		game.StarterGui.KickGUI.Enabled = false 
		script.Parent.Text = "ACTIVATED"
	else if game.StarterGui.KickGUI.Enabled == false then
		game.StarterGui.KickGUI.Enabled = true
		script.Parent.Text = "Slap Out! *FOR GAMEPASS*"
				
		end 

		end
	else
		script.Parent.Text = "no gamepass "
		wait(1)
		script.Parent.Text = "Slap Out! *FOR GAMEPASS*"
	end
	
end)

This is the button in game:
image

Here is the gui in the workspace: Ignore the NPC one, and the empty kick gui, is used as a kind of checking tool, where the enabled property is changed to false, if they player clicks the button in the game. image

2 Likes

It’s complicated :upside_down_face:
you cannot use this code : game.StarterGui.KickGUI

1 Like

Why not? text

2 Likes

Everything from StarterGui gets replicated to PlayerGui. Meaning, accessing anything from StarterGui at runtime will change nothing visually or internally

2 Likes

Oh, Let me see if that helps fix it.

2 Likes

To explain further what @The_flyingMan716 said you want to index Playergui not StarterGui Indexing StarterGui will edit the Gui’s before players receive them you want to index Player.AlsoGuiButton | Roblox Creator Documentation has no parameters so using player as a parameter wouldn’t work I think you believed it was ClickDetector | Roblox Creator Documentation

local MarketplaceService = game:GetService("MarketplaceService")
local Players= game:GetService("Players")
local Player = Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local ScreenGui = PlayerGui.ScreenGui
local TextButton = ScreenGui.TextButton

TextButton.MouseButton1Click:Connect(function()
	local OwnsGamepass = UserOwnsGamePassAsync(Player.UserId, 23171784)
	if OwnsGamepass then
		if KickGUI.Enabled == true then
			KickGUI.Enabled = false 
			TextButton.Text = "ACTIVATED"
		elseif KickGUI.Enabled == false then
			KickGUI.Enabled = true
			TextButton.Text = "Slap Out! *FOR GAMEPASS*"
		end
	else
		TextButton.Text = "no gamepass "
		wait(1)
		TextButton.Text = "Slap Out! *FOR GAMEPASS*"
	end
end)
2 Likes

Oh, oof. I’m still not too good, so I guess I’m making some easy mistakes.

I made a mistake I thought the textButtons were within ScreenUI at first but changed it to kickGUI one second

fixed.

Give me a second to implement it real quick.

So nothing has to be changed in the server script correct? And, also this should work correct:

local mps = game:GetService("MarketplaceService")
local plr = game.Players.LocalPlayer	
script.Parent.MouseButton1Click:Connect(function()
	
	if plr and mps:UserOwnsGamePassAsync(plr.UserId, 23171784) then
	if plr:WaitForChild("PlayerGui").KickGUI.Enabled == true then
		plr:WaitForChild("PlayerGui").KickGUI.Enabled = false 
		script.Parent.Text = "ACTIVATED"
	else if plr:WaitForChild("PlayerGui").KickGUI.Enabled == false then
		plr:WaitForChild("PlayerGui").KickGUI.Enabled = true
		script.Parent.Text = "Slap Out! *FOR GAMEPASS*"
				
		end 

		end
	else
		script.Parent.Text = "no gamepass "
		wait(1)
		script.Parent.Text = "Slap Out! *FOR GAMEPASS*"
	end
	
end)
1 Like

The variables and changes I made was for the code to run more efficiently and remove the redundancies and making it easier to read

Still doesn’t work.fafsf

I fixed my example for it to work and be easy to read. It seems it should work but. You don’t really need to ask me you can simply run the code.

Redundancies(things you should remove)
else if | you do this on line 10 forcing you to write another end just remove the space between making it elseif

if plr and | you don’t need this your code is clientside it needs player to even run in general

Can you use the example i made I’m confused on why you refuse to?

Yeh, I tried your example. I can try it again though if you wish.

I copy and pasted your again, let me test again.

was afk Here it was further up.

Still doesn’t work, I copy and pasted, with nothing missing, there were a few errors, and I fixed them.

Few errors like what? I probably index somethings incorrectly.

Yeah, for example:

local Player = Player.LocalPlayer

instead of

local Player = Players.LocalPlayer

So, nothing really bad just a typo.

1 Like