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

how do i fix this removet event?

the local script in starter pack

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local we = false

mouse.KeyDown:Connect(function(key) -- lol i tryed keyheld ;-;
    key = key:lower()
    if key == "e" then
game.ReplicatedStorage.RemoteEvent:FireServer()
		
	end
	end)

the reg script in work place

		--this is the script one who is listing
	-- just a script in workplace
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function()
		game.Players.PlayerAdded:Connect(function(player)
			local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local we = false
		local x = Instance.new("Part",workspace)
		x.Shape = "Ball"
		x.BrickColor = BrickColor.new("Maroon") 
		x.Transparency = .5
		x.BottomSurface = "Smooth"
		x.TopSurface = "Smooth"
		x.CanCollide = false
		x.Anchored = false
		x.CFrame = player.Character.LowerTorso.CFrame * CFrame.new(0,0,-6)
		local v = Instance.new("BodyVelocity",x)
		v.Velocity = player.Character.Head.CFrame.lookVector * 90 --mouse.Hit.lookVector* 90
		v.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
		local clone = game.Lighting.Fire:Clone()
		clone.Parent = x
	x.Name = "flame"
		
		local boo = script.Parent.dmg.flame:Clone()
			boo.Disabled = false
		boo.Parent = x
		wait(2)
	x:Remove()
	end)
end)

3 comments

0

I believe the fireserver function has to have an argument, as well as the onserverevent function... try that.

0

If incapaz helped you, you should accept his answer.

0

nvm i thought i did

1 answer

✓ Accepted answer

###The problem with your script is that you're nesting PlayerAdded events to OnServerEvent, so each time FireServer is called, you have all of these connections. The OnServerEvent passes the player as a parameter, so use that instead. LocalPlayer and Mouse cannot be used on the server, only on the client.

--local script that fired event
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local we = false
local inputservice = game:GetService("UserInputService")

inputservice.InputBegan:Connect(function(key, gpe)
    if gpe then return end -- if they're chatting, end the function 
    
    if key.KeyCode == Enum.KeyCode.E then
        game.ReplicatedStorage.RemoteEvent:FireServer()
    end  
end)

-- back in the server script 
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
    local x = Instance.new("Part") -- parent argument deprecated
    x.Shape = Enum.PartType.Ball -- use enums 
    x.BrickColor = BrickColor.new("Maroon") 
    x.Transparency = .5
    x.BottomSurface = Enum.SurfaceType.Smooth
    x.TopSurface = Enum.SurfaceType.Smooth
    x.CanCollide = false
    x.Anchored = false
    x.CFrame = player.Character.LowerTorso.CFrame * CFrame.new(0,0,-6)
    x.Parent = workspace -- assign parent last to reduce lag

    local v = Instance.new("BodyVelocity")
    v.Velocity = player.Character.Head.CFrame.lookVector * 90 --mouse.Hit.lookVector* 90
    v.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
    v.Parent = x

    local clone = game.ServerStorage.Fire:Clone() -- use Server/Replicated Storage
    clone.Parent = x
    x.Name = "flame"

    local boo = script.Parent.dmg.flame:Clone()
    boo.Disabled = false
    boo.Parent = x
    wait(2)
    x:Destroy() -- Remove is deprecated use Destroy
end)

###On a side note, KeyDown, the Instance.new parent argument, Remove, and using Lighting as storage are deprecated, use InputBegan of UserInputService, assign the parent last, use Destroy, and use ServerStorage or ReplicatedStorage to store objects.

1 comment

0

Thank u so much

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