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.
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:
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.
Everything from StarterGui gets replicated to PlayerGui. Meaning, accessing anything from StarterGui at runtime will change nothing visually or internally
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)
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)
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