I have a butterfly model that i made. I set it up so that when you click it it plays and animation and dissapears. it is suppose to kill the player aswell. but i can not seem to get the players model. to kill.
The mouseclick function returns the players folder and i don’t know how to go about using that info to get the players model.
local clicked = false
local cursor = script.Parent.Part.ClickDetector
fly:Play()
fly.Looped = true
cursor.MouseClick:Connect(function(plr)
if clicked == false then
clicked = true
flip:Play()
plr.Curse.Value = true
--KillPlayer:FireClient(plr) (Doesn't work not the player model)
flip.Looped = false
flip.Stopped:Wait(3)
Model:Destroy()
end
end)
Ok i believe that works. but my character is not dying. im not sure what going on but i don’t get any errors, the code runs through it just doesn’t kill my character. heres the script for the killPlayer event. It accounts for Player.Character.
it just wont kill the player.
local handler = game.ReplicatedStorage.RemoteEvents.KillPlayer
handler.OnServerEvent:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
humanoid:TakeDamage(99999)
if humanoid.Health > 0 then
humanoid.Health = 0
end
end)
Its used throughout the game for other parts and it works just fine.
local handler = game.ReplicatedStorage.RemoteEvents.KillPlayer
handler.OnServerEvent:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
humanoid:TakeDamage(99999)
if humanoid.Health > 0 then
humanoid.Health = 0
end
end)
ClickDetectors are registered on the server, not the client. In a server script:
local function main(plyr : Player)
-- Find the player's humanoid
local hum : Humanoid = plyr:FindFirstChildOfClass("Humanoid")
-- Damage the player
hum:TakeDamage(int)
end
model.ClickDetector.MouseClick:Connect(main)
Moved it to server scripts. wrote this new code. Worked once and proceeded not to work at all. i think its some kind of glitch.
local KillPlayer = game.ReplicatedStorage.RemoteEvents.KillPlayer
local Butterflys = game.Workspace.Butterflys
local clicked = false
local value = 150
for _, BFlys in pairs(Butterflys:GetChildren()) do
local cursor = BFlys.Part.ClickDetector
local flip = BFlys.PlayAnimation.Flip
local Flyanimation = BFlys.PlayAnimation.Flying
local FlipAnimation = BFlys.PlayAnimation.Flip
local humanoid = BFlys.Humanoid
local fly = humanoid:LoadAnimation(Flyanimation)
local flip = humanoid:LoadAnimation(FlipAnimation)
cursor.MouseClick:Connect(function(plr)
local player = plr.Character
if BFlys.Name == "GoldButterfly" then
local sparkles = BFlys["Shiny sparkle"]
if clicked == false then
clicked = true
flip:Play()
plr.Currency.Value = plr.Currency.Value + value
sparkles:Play()
flip.Looped = false
flip.Stopped:Wait(3)
BFlys:Destroy()
clicked = false
end
end
if BFlys.Name == "BlackButterfly" then
if clicked == false then
clicked = true
flip:Play()
plr.Curse.Value = true
wait()
player.Humanoid:TakeDamage(99999)
flip.Looped = false
flip.Stopped:Wait(3)
BFlys:Destroy()
clicked = false
end
end
end)
end